qstandarditemmodel

Items disappears from combo box when I read them from model

纵然是瞬间 提交于 2019-12-02 09:28:40
问题 I have QComboBox and I set QStandardItemModel because I need multi-select check-boxes in it. Problem is that when I read text value and check state of items in comboBox, they disappear from combo. This is how I set model to comboBox: areas = ["Area one", "Area two", "Area three", "Area four"] model = QtGui.QStandardItemModel(4, 1)# 4 rows, 1 col for i,area in enumerate(areas): item = QtGui.QStandardItem(area) item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) item.setData

How to serialize a QAbstractItemModel into QDataStream?

那年仲夏 提交于 2019-12-01 18:01:41
I've set up a QAbstractItemModel and filled that with data. My QTreeView widget displays every data in that model properly. Now, I would like to store that model serialized in a binary file (and later of cource load that binary file back into a model). Is that possible? The particulars of model serialization depend somewhat on the model's implementation. Some gotchas include: Perfectly usable models might not implement insertRows / insertColumns , preferring to use custom methods instead. Models like QStandardItemModel may have underlying items of varying types. Upon deserialization, the

Add items to columns in QStandardItemModel

不羁岁月 提交于 2019-12-01 10:51:28
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? 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 each column, e.g.: QList<QStandardItem *> items; items.append(new QStandardItem("Column 1 Text")); items.append

How to Copy - Paste Multiple Items form QTableView created by QStandardItemModel to a text/excel file?

你说的曾经没有我的故事 提交于 2019-11-30 09:44:38
问题 How can I copy and paste multiple items/values of a QTableView to a text/ excel file? My Code: tab_table_view = QtGui.QWidget() self.Tab.insertTab(0, tab_table_view, self.File_Name) self.tableView = QtGui.QTableView(tab_table_view) self.tableView.setGeometry(QtCore.QRect(0, 0, 721, 571)) self.model = QtGui.QStandardItemModel(self) self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection This line self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection helps with

How to Copy - Paste Multiple Items form QTableView created by QStandardItemModel to a text/excel file?

*爱你&永不变心* 提交于 2019-11-29 16:52:32
How can I copy and paste multiple items/values of a QTableView to a text/ excel file? My Code: tab_table_view = QtGui.QWidget() self.Tab.insertTab(0, tab_table_view, self.File_Name) self.tableView = QtGui.QTableView(tab_table_view) self.tableView.setGeometry(QtCore.QRect(0, 0, 721, 571)) self.model = QtGui.QStandardItemModel(self) self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection This line self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection helps with selecting multiple items in QTableView but when I do CTRL + C and paste it only pastes the last item or value

QComboBox with checkboxes

与世无争的帅哥 提交于 2019-11-29 11:14:13
I'm creating QComboBox with checkboxes. How I can prevent collapsing of view on mouse clicking? I want to be able to set up checkboxes, but each time I click on item - drop-down of QComboBox is collapsed. Note: currently I'm debugging Qt sources and looking for workaround... First of all you need to install an event filter to the combo box view, i.e.: combobox->view()->viewport()->installEventFilter(someobj); than you need to filter all mouse release events that happen on the combo box view to prevent its closing when you click on it: bool SomeObject::eventFilter(QObject *obj, QEvent *event) {