QTableWidget cellwidget selection
I have a qtablewidget, which i populated with widgets (setCellWidget()). So it doesnt contain any QTableWidgetItems, but only widgets.
I can select the widgets in the table - but how do i get a list of selected cells?
All the IsSelected() stuff operates on QTableWidgetItems, which i dont have.
there is a method to return indexes (QModelIndexList), but it's protected and i cant access it.
how do i do it?
Re: QTableWidget cellwidget selection
Hi,
If you want to get selected item in QTableWidget, you can use :
Best regards,
Toto
Re: QTableWidget cellwidget selection
yes, but i dont have any items, only widgets. So that call always returns an empty list, because no items exists to begin with.
Re: QTableWidget cellwidget selection
Since QTableWidgetItem is not a QObject, you can try and create a widget which subclasses from QTableWidgetItem:
Then you can cast your pointer to both QWitdget and QTableWidgetItem allowing you use it both in setCellWidget as well as setItem() allowing you to use the model view part for the selctions and the visible part of cell widget.
I never tried it so no warranty on this ;-)
Re: QTableWidget cellwidget selection
clever & sneaky! ;)
I'll give it a shot later on, but it doesnt feel very clean. If someone know an "official" way, please do tell.
Re: QTableWidget cellwidget selection
What is not clean is the way you are using QTableWidget.
It is an item based widget, and you are not using it with items which is what my solution actually solves.
It wont get much cleaner or more "official" than that - except a proper usage of items.
Re: QTableWidget cellwidget selection
is there a better/more official way to use QWidgets in a "table-like" way?
Anyways, you solution works just fine. Thanks!
Re: QTableWidget cellwidget selection
The question is what exactly you are trying to achieve.
You said very little about the motivation or requirements of what you are doing, so its hard to say.
It sounds almost as what you really need is not a table but a layout.
But I can't really tell based on what you have supplied so far.