qtableview

How to change cell's background color of a QTableView [duplicate]

流过昼夜 提交于 2019-12-20 03:51:28
问题 This question already has answers here : background color of cells in QTableview, PySide2 (1 answer) PyQt Tableview background color based on text value rather than True or False (1 answer) Closed 6 months ago . I have a table view displaying a QAbstractTableModel, I managed to color a row within the data function but I just want to color the cell and not the entire row. i.e if the cell value = "In error" I want to color it in red I have tried to set a color to the cell using the setData

How to change background color after editing QTableView cell?

喜欢而已 提交于 2019-12-19 19:42:46
问题 i have this QTableView with custom model and delegate, how do i change the background color of the cell after editing it? shall i do this in delegate's setModelData() ? index.model.setData(index, QVariant(True),Qt.UserRole) and later in model's data() # it's calling itself ? if role == Qt.BackgroundColorRole: if index.model().data(index,Qt.UserRole).toBool(): return QVariant(QColor(Qt.darkBlue)) and in model's setData() i don't have any code like: if role==Qt.UserRole: .... what is the

Add items to columns in QStandardItemModel

ぐ巨炮叔叔 提交于 2019-12-19 10:14:35
问题 I am currently adding rows to my QTableView as such QStandardItem* itm; QStandardItemModel* model = new QStandardItemModel(this); model->setColumnCount(2); model->appendRow(new QStandardItem("Some Text in Column1"); How do I add items to column 2 dynamically by appending? In the above example column 2 is empty. How do I add item to column 2? 回答1: Calling appendRow(QStandardItem *) only adds a single item to the first column. You would need to pass in a QList to appendRow() to add items to

Connecting QTableView selectionChanged signal produces segfault with PyQt

半腔热情 提交于 2019-12-19 06:21:48
问题 I have a QTableView in a PyQt application, and I want to keep track of when the selection changes. I've tried connecting the signal to a slot as follows (using the advice on this page: self.view.selectionModel().selectionChanged.connect(self.selChanged) where the slot it is connected to is defined as: def selChanged(self, selected, deselected): print "Sel changed" However, whenever I load the QMainWindow on which the QTableView resides, I get an immediate segmentation fault. Am I doing

Connecting QTableView selectionChanged signal produces segfault with PyQt

烈酒焚心 提交于 2019-12-19 06:21:15
问题 I have a QTableView in a PyQt application, and I want to keep track of when the selection changes. I've tried connecting the signal to a slot as follows (using the advice on this page: self.view.selectionModel().selectionChanged.connect(self.selChanged) where the slot it is connected to is defined as: def selChanged(self, selected, deselected): print "Sel changed" However, whenever I load the QMainWindow on which the QTableView resides, I get an immediate segmentation fault. Am I doing

How to display content of multiple QSqlTableModels in one QTableView?

人盡茶涼 提交于 2019-12-19 04:58:32
问题 I have a MySql table, let's call it x : CREATE TABLE x ( Id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, A int unsigned NOT NULL, B int, FOREIGN KEY (A) REFERENCES y(Id) ); And then I have another table, let's call it y : CREATE TABLE y ( Id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, First varchar(255), Last varchar(255) ); I want to display table x in one QTableView and in place of column A from table x I want to display columns First and Last from table y from row whose Id is

how to get selected rows in QTableView

感情迁移 提交于 2019-12-18 10:28:00
问题 After watching many threads about getting selected rows numbers, I am really confused. How do you get ROW numbers in QTableView using QStandardItemModel I used below selection model and behavior as setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::SingleSelection); and if you have your own way of selecting can you explain how it works. Thanks for the help! 回答1: The method selectionModel() return a QItemSelectionModel . You can use QItemSelectionModel

how to get selected rows in QTableView

蓝咒 提交于 2019-12-18 10:27:39
问题 After watching many threads about getting selected rows numbers, I am really confused. How do you get ROW numbers in QTableView using QStandardItemModel I used below selection model and behavior as setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::SingleSelection); and if you have your own way of selecting can you explain how it works. Thanks for the help! 回答1: The method selectionModel() return a QItemSelectionModel . You can use QItemSelectionModel

How to create a filter for QTableWidget?

删除回忆录丶 提交于 2019-12-18 04:29:11
问题 I'm trying to create a filter for QTableWidget with QLineEdit in PySide. I've seen some tutorials using QSortFilterProxyModel for C++ but couldn't understood how to do it in Python. I need to search in 'VALUE' column. 回答1: A QSortFilterProxyModel is a proxy model, that means that you put it between the your complete data model and a view. The comment by titusjan is good, you can look in your local PySide/PyQt installation for basicsortfiltermodel.py to get an example in Python. Also, instead

Set color to a QTableView row

我只是一个虾纸丫 提交于 2019-12-18 03:37:08
问题 void MyWindow::initializeModelBySQL(QSqlQueryModel *model,QTableView *table,QString sql){ model = new QSqlQueryModel(this); model->setQuery(sql); } With this method i can set a QSQlQueryModels to my QTableviews. But How i can set color to a row based on a cell value? 回答1: The view draws the background based on the Qt::BackgroundRole role of the cell which is the QBrush value returned by QAbstractItemModel::data(index, role) for that role. You can subclass the QSqlQueryModel to redefine data()