PDA

View Full Version : QTreeWidget, resizing item and widgets problem



The Storm
15th March 2008, 17:03
Hi all,

I will explain basicly - I have items with icons and some text on it, when item is clicked I place a widget on it, so far so good, but when the treewidget is resized the icon of the item below the widget is showing up, how I can avoid this to happen, here two screenshots to make it more clear.

The first screen is the correct effect before to resize the TreeWidget, and the second is after I resized the TreeWidget, as you see the icon of the item that is under the widget shows up and I don't want that to happen. :)

wysota
16th March 2008, 06:53
What does the embedded widget consist of?

The Storm
16th March 2008, 11:46
The base is QFrame, on that frame there is 3-4 QLabels with CSS styling, thats all. :)

yogeshm02
16th March 2008, 12:00
Did the embedded widget changed its size ever when you resized the tree widget?

wysota
16th March 2008, 12:57
The base is QFrame, on that frame there is 3-4 QLabels with CSS styling, thats all. :)

When you set an index widget, the item background shines through. If the content is transparent (like labels and frames are), it will shine through unless you do one of two things:
1. Make sure the delegate doesn't paint anything while the index widget is set
2. Make the frame paint its background.

The Storm
16th March 2008, 13:56
@yogeshm02 The QTreeWidget automatically resize my QFrame widget when I resize the QTreeWidget and sinse I use the QFrame resize event I can position the widget inside in correct but it seems that QTreeWidget isn't resizing the QFrame correct and the little smile of the item shows up. :(

@wysota
1. I don't use QItemDelegate, I use setItemWidget() function but if you meant other thing just tell me :).
2. I use setAutofillBackground(true) to my QFrame widget if it's that whats you meant but no change... :(

wysota
16th March 2008, 14:18
@wysota
1. I don't use QItemDelegate,
Of course you do. Each cell is painted using a delegate and the default delegate is QItemDelegate or QStyledItemDelegate since Qt 4.4.


2. I use setAutofillBackground(true) to my QFrame widget if it's that whats you meant but no change... :(
Try changing the palette of the frame (especially the Window role) to see if the background of the frame gets painted.

The Storm
16th March 2008, 15:46
Of course you do. Each cell is painted using a delegate and the default delegate is QItemDelegate or QStyledItemDelegate since Qt 4.4.


Try changing the palette of the frame (especially the Window role) to see if the background of the frame gets painted.

I hope that this is what you meant (attached picture) and how can I be sure that this QItemDelegate doesn't paint anything while there is widget on it.

wysota
16th March 2008, 16:33
I hope that this is what you meant (attached picture)
Yes. You can see that the frame doesn't span across the whole item. Could you show us the code for the widget you set as the index widget?


and how can I be sure that this QItemDelegate doesn't paint anything while there is widget on it.
Remove the icon when you set the index widget.

The Storm
16th March 2008, 16:54
Here's the code


ContactWidget *pContactWidget = new ContactWidget();
pContactWidget->setAutoFillBackground(true);
/* Setting some data to the QLabels inside the pContactWidget */
pContactView->setItemWidget(selectedItem, 0, pContactWidget);


ContactWidget - my class that inherits QFrame
pContactView - this is the QTreeWidget

Sure removing of the icon from the item before setting the widget fix the problem but this was the thing I want to avoid because when the user click on other contact from the list I must set the icon of the item again and sinse my code is not very well constructed this is ugly task to be done but if there is no other way I will remove that icon before setting the widget. :)

wysota
16th March 2008, 17:54
Do you have a hierarchy of items or is your data model flat? Did you modify any properties in ContactWidget? What does the constructor look like?

The Storm
16th March 2008, 18:44
I don't use model, I'm directly creating new items, I do nothing in to my class that inherits QFrame, thats are future plans but I will show. :)


class ContactWidget : public QFrame
{
Q_OBJECT

public:
ContactWidget(QWidget *parent = 0) : QFrame(parent) {};
~ContactWidget() {};
};

wysota
16th March 2008, 20:11
I don't use model, I'm directly creating new items,
It's still a data model. So do you organize your items in a flat structure or a graph (parent-child relationship)?

The Storm
16th March 2008, 21:39
It's flat structure, there is no childs. :)

wysota
16th March 2008, 23:44
Could you just for testing issue such code and show us the result?


selectedItem->setData(Qt::blue, Qt::BackgroundRole);

The Storm
17th March 2008, 21:20
Ah I'm sorry but I already do remove the icon before setting the widget and all is fine, so I don't have what to show after I put this line of code, but if you really want to I will make some changes and make screenshot. :)