How to add a combobox in qtablewidget?
-
Hello, I want to add a combobox in qtablewidget. I searched the internet but only found 1 sample in pyqt. Any help for Qt5?
https://stackoverflow.com/questions/30457935/pyqt4-adding-combobox-in-qtableview
-
If you read the code carefully you will notice that it doesn't have that much difference between the C++ and Python in that case as Qt maintain its API for both language.
The secret lies here:
setCellWidget
. https://doc.qt.io/qt-5/qtablewidget.html#setCellWidget -
@MasterBlade said in How to add a combobox in qtablewidget?:
Hello, I want to add a combobox in qtablewidget. I searched the internet but only found 1 sample in pyqt. Any help for Qt5?
https://stackoverflow.com/questions/30457935/pyqt4-adding-combobox-in-qtableview
Yes I finally found it. Thanks for that.
My problem is that I can't locale the row# of the table.
I used the followings. But only get -1 for row.
QModelIndex index = ui->Subtype->indexAt(mapFromGlobal(QCursor::pos()));
int row = index.row();The table is only a part of the window. Will that matter?
-
The correct way is using a delegate, see https://forum.qt.io/topic/88486/dropdown-in-qtablewdget/3. You just need to translate that into python