qabstracttablemodel

Using a QCompleter in a QTableView with Qt and Python

别等时光非礼了梦想. 提交于 2019-12-14 02:43:57
问题 I'm reading up on how to make my QAbstractTableModel editable, and it looks pretty straightforward. But how do I set up an editable cell to use a QCompleter? I take it somehow I have to tell the QTableView to use a QLineEdit widget? How can I do this? edit: hmm, I guess it has something with QTableView.setItemDelegateForColumn() but I don't know anything about delegates or how to use them. edit: I tried RobbieE's solution, got something that sort of works but it gets the geometry of the popup

QAbstractTableModel retrieve custom object on data changed

﹥>﹥吖頭↗ 提交于 2019-12-13 12:23:11
问题 I have recently picked up Qt again, and started refreshing my memory. Creating a custom data model for a table was easy enough. Now I am trying to retrieve the selected data. Take note that I use custom data objects. Example of my custom model: platform.h class Platform { public: Platform(); Platform(QString name); QString getName(); void setName(QString name); private: QString m_name; }; Very simple data structure for testing purposes. I then implemented a QAbstractTableModel, the Data()

Tooltip is not updated on moving from one row to another

大憨熊 提交于 2019-12-13 05:45:35
问题 I have subclassed QAbstractTableModel and in data() function I am displaying an image in last column of each row and a tooltip on mouse hover. QVariant MyTableModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); if (role == Qt::DisplayRole) { switch (index.column()) { // few cases default: return QVariant(); } } else if (role == Qt::CheckStateRole && index.column() == 0) { int state= tableData.at(index.row()).state; if (state) return Qt::Checked;

Qt QAbstractModel: remove checkbox

半城伤御伤魂 提交于 2019-12-12 06:27:16
问题 I started to learn Qt, and I would like to implement a table filled with data via QTableView. My problem is, that I don't know how to remove the checkboxes from the cells. It seems like they are put in by default. However, I read that I had to return a NULL-QVariant, but that's not what I was looking for as I still have data to put in. That's my code so far: QVariant MyModel::data(const QModelIndex &index, int role) const { int row = index.row(); int col = index.column(); QString daten;

PyQt QAbstractTableModel checkbox not checkable

孤街浪徒 提交于 2019-12-11 18:57:12
问题 I am using own table model with QAbstractTableModel, where I have first col with checkbox (checkable cause flags Qt.ItemIsUserCheckable | Qt.ItemIsSelectable | Qt.ItemIsEnabled ). I have trouble when I am trying use checkboxes, cause they are not checkable (can not make check or uncheck in them) in showed table. What am I doing wrong? I am using this methods in own table model class: def data(self, index, role): row = index.row() col = index.column() if role == Qt.DisplayRole: return '{0}'

how can i achieve to update multiple rows in a qtableview

安稳与你 提交于 2019-12-08 07:28:52
问题 I have a customized qtablemodel and a qtableview. I would like to add a feature that the user can select multiple rows and by changing one of the values within this rows. He would actually change this value in all rows. e.g. the user could change the name of all persons in the table to alice when he selected the whole table. Can you help me to achieve this? I do not understand how i can trigger the setData of the model a multiple times for different rows. Or can you tell me which signal the

QAbstractTableModel retrieve custom object on data changed

独自空忆成欢 提交于 2019-12-04 20:11:51
I have recently picked up Qt again, and started refreshing my memory. Creating a custom data model for a table was easy enough. Now I am trying to retrieve the selected data. Take note that I use custom data objects. Example of my custom model: platform.h class Platform { public: Platform(); Platform(QString name); QString getName(); void setName(QString name); private: QString m_name; }; Very simple data structure for testing purposes. I then implemented a QAbstractTableModel, the Data() method looks like this: platformmodel.cpp QVariant PlatformModel::data(const QModelIndex &index, int role)

What is the best way to display an animated icon in a QTableView?

别说谁变了你拦得住时间么 提交于 2019-12-04 10:34:48
问题 I've been struggling with this for some times now, and I can't seem to find the right way to do this. What I would like is the ability to use an animated icon as a decoration for some of my items (typically to show that some processing is occuring for this particular item). I have a custom table model, that I display in a QTableView . My first idea was to create a custom delegate that would take care of displaying the animation. When passed a QMovie for the decoration role, the delegate would

Qt Delete selected row in QTableView

时光总嘲笑我的痴心妄想 提交于 2019-12-04 01:09:51
问题 I want to delete a selected row from the table when I click on the delete button. But I can't find anything regarding deleting rows in the Qt documentation. Any ideas? 回答1: You can use the bool QAbstractItemModel::removeRow(int row, const QModelIndex & parent = QModelIndex()) functionality for this. Here you can find an example for all this. Also, here is an inline quote from that documentation: removeRows() Used to remove rows and the items of data they contain from all types of model.

How to set row height of QTableView?

点点圈 提交于 2019-12-02 17:29:52
I have QTableView and QAbstractTableModel . I require rows to have height equal to 24. I know the only way to do this is by calling QTableView::setRowHeight . Since the model is dynamic it may be added new rows, but I don't want to call setRowHeight each time new row is added. How can I configure QTableView such that it uses the same height for new added rows or can a model be sent the height of rows? For Qt versions < 5 QHeaderView *verticalHeader = myTableView->verticalHeader(); verticalHeader->setResizeMode(QHeaderView::Fixed); verticalHeader->setDefaultSectionSize(24); For Qt versions >= 5