qtableview

How to get Index Row number from Source Model

匆匆过客 提交于 2019-12-25 00:32:08
问题 Clicking the QTableView " Item_B_001 " prints out its row number # 0 . But in source model's self.items this item corresponds to the number # 3. How to get a "real" Source Model's Item's row number - a number it really corresponds to? from PyQt4.QtCore import * from PyQt4.QtGui import * import sys class Model(QAbstractTableModel): def __init__(self, parent=None, *args): QAbstractTableModel.__init__(self, parent, *args) self.items = ['Item_A_001','Item_A_002','Item_B_001','Item_B_002'] def

Make item delegate in QTableView not transparent

◇◆丶佛笑我妖孽 提交于 2019-12-24 23:09:24
问题 I issued in problem with custom item delegate for QTableView. That problem is completely illustrated by that screenshoot: We can see item content behind item delegate editor. What is the best way to hide that content or make item delegate not transparent? (how I can get background color/brush for edited row?) 回答1: You need to let your editor to paint its own background by enabling the autofill background property: editor->setAutoFillBackground(true); 回答2: widget->setStyleSheet("background

How to refresh QTableView when it is driven by model

痴心易碎 提交于 2019-12-24 18:12:33
问题 The code below creates QTableView driven by self.myModel ( QAbstractTableModel ). 'Show All' self.checkBox is linked to self.myModel.cbChanged() method. Question: How to modify this code so 'QTableView' gets refreshed as soon as checkbox is checked? The goal: when the checkbox is checked we want the odd numbered items to be displayed. And the even numbered items to be hidden. When the checkbox is off (unchecked) we want the even numbered items to be displayed. All the odd numbered items are

popup of QTableView doesn't show well

痴心易碎 提交于 2019-12-24 15:26:10
问题 I have a QTableView which show the content in popup when the mouse hover on it. In most cases it works well, but sometimes when I move the mouse, the popup become transparency. I have go through the code but still don't find out the reason. The correct case and incorrect case are shown below. The code related to this popup is shown below: bool eventFilter(QObject *watched, QEvent *event){ if(viewport() == watched){ if(event->type() == QEvent::MouseMove){ QMouseEvent *mouseEvent = static_cast

How to auto stretch QTableView columns and keep them being adjustable

大憨熊 提交于 2019-12-24 12:05:09
问题 I really like a clean result of self-adjusting to the QTableView 's width of the columns using: self.view.horizontalHeader().setResizeMode(QHeaderView.Stretch) But unfortunately with this flag used the columns width doesn't stay adjustable any longer (the user is not able to resize the columns width). I wonder if there is an alternative way to set the columns width to the width of the QTableView and yet keeping the columns width "user-adjustable"? from PyQt4.QtCore import * from PyQt4.QtGui

QTableView sort column data by UserRole

流过昼夜 提交于 2019-12-24 11:44:26
问题 I have a QStandardItemModel piped into a QTableView. One of the columns in my model contains dates which have user-friendly displayData and computer-friendly userData. So for example one QStandardItem might display a string like 22 Nov 2018 but the userdata would look like 324586 (seconds since the epoch). However when I sort the column it of course sorts by the displayData. How can I force the table to sort by userData instead? 回答1: You have to use setSortRole(): from PyQt5 import QtCore,

add feature for previous question PySide2 QListView and QTableView

99封情书 提交于 2019-12-24 10:15:12
问题 The previous question was PySide2 QListView QTableView sync problem Imagine to have another dict4 in the data structure: 'dict4':{'k8':'v8', 'EXISTING_DICT':'dict2'}, Meaning, that a dictionary could include another existing dictionary. So the representation in the QTableView shouldn't be directly showed, but: 1) Show just the name of it in the QTableView: k1 | v1 ------- k2 | v2 ------- k3 | v3 ------- dict2 2) If double click it on it: select the existing dictionary in the QListView, which

selected item of comboBox in custom Delegate from QTableView

萝らか妹 提交于 2019-12-24 02:28:08
问题 I use a custom delegate to display a column of comboBoxes in my QTableView. The values are the same for all the comboBoxes so it's not really the population part that gives me trouble. I want them to show as the selected item, some value that I can retrieve from a database. I have access to the database from the delegate, but in order to send my request, I need the row of the comboBox. So I guess my question is : how can you iterate over all the rows of the table and do some action from

PyQt - Load SQL in QAbstractTableModel (QTableView) using pandas DataFrame - editing datas in a GUI

房东的猫 提交于 2019-12-24 02:09:12
问题 I'm quite new to python and using WinPython-32bit-2.7.10.3 (including QTDesigner 4.8.7 ). I'm trying to program an interface for using a sqlite database on two separates projects, using QtableViews. The algorithm is roughly so : - connect to database and convert datas to pandas.DataFrame - convert DataFrame to QAbstractTableModel - apply the QAbstractTableModel to the tableview.model - load the dialog I don't get the same comportment, depending of the sql used to create the dataframe : given

How to set width of QTableView columns by model?

别说谁变了你拦得住时间么 提交于 2019-12-23 14:59:20
问题 I'm using QTableView with a subclass of QAbstractTableModel as its model. By implementing data() and headerdata() in the subclassed model, it is feasible to control many properties of the table like data, header values, font, and so on. In my case, I want the model to set the width of each table column. How can this be done? 回答1: There are two ways: In your model's data method you can return the role SizeHintRole. A better way would be to subclass QItemDelegate and override the method. See