PDA

View Full Version : Selection of cell with QWidget in QTableWidget



Tamara
14th February 2007, 16:37
Situation:
- create QTableWidget
- all cells could be selected by mouse clicking
- place a QWidget to a cell
- click the cell - and it is not selected!
To select such cells I have to catch mouse clicking event, and make some manipulations with selection model....
May be there is more simple way? Or it is Qt-bug?

jpn
14th February 2007, 19:47
To select such cells I have to catch mouse clicking event, and make some manipulations with selection model....
May be there is more simple way? Or it is Qt-bug?
No, it's not a bug but the desired behavior. The cell widget is a separate widget on top of the view and receives events belonging to it.

Disclaimer: Using cell/item/index widgets for the item views is in many cases a bad idea and should not be abused. Having too many (child) widgets is expensive in general. With item views, maintaining their geometries is also somewhat expensive, depending on the complexity of the view.

Anyway, what does the cell widget do? Maybe you could use a custom delegate (+ editors) instead of permanent cell widgets?

Tonal
16th February 2007, 05:23
Anyway, what does the cell widget do? Maybe you could use a custom delegate (+ editors) instead of permanent cell widgets?
How to display Rich text in cells?
How to display simple text with small interactive area: hyperlink or info button?

jpn
16th February 2007, 13:18
How to display Rich text in cells?
Use a custom delegate. See for example this post (http://www.qtcentre.org/forum/p-qstandarditem-subpart-of-the-text-as-bold-post28758/postcount4.html).


How to display simple text with small interactive area: hyperlink or info button?
Use a custom delegate. Catch the required mouse press/release events and such via QAbstractItemDelegate::editorEvent().

Tonal
17th February 2007, 11:47
Use a custom delegate. Catch the required mouse press/release events and such via QAbstractItemDelegate::editorEvent().
No.
How to highlight interactive area with mouse hover?

jpn
17th February 2007, 12:10
No.
How to highlight interactive area with mouse hover?
You'll get mouse move events too if mouse tracking is enabled on the view.

Tonal
17th February 2007, 13:57
You'll get mouse move events too if mouse tracking is enabled on the view.
And emulate enterEvent leaveEvent for cells and interactive areas...
Maybe simplify insert QLabel in cell?
But if insert QLabel selection model do not work. :(

jpn
17th February 2007, 14:11
And emulate enterEvent leaveEvent for cells and interactive areas...
Maybe simplify insert QLabel in cell?
But if insert QLabel selection model do not work. :(
Sure it might simplify many things to use separate widgets. But the point was that the program will end up being a resource hog when the amount of cell/item/index widgets is high. Originally in Qt 4.0 there was no such thing as cell/item/index widgets. I guess the feature was added because so many people demanded it. The more I see these problems the more I'm convinced one should rarely use them. It's a feature which makes it easy for people to shoot themselves in the foot. ;)