2 Attachment(s)
QTreeWidget, resizing item and widgets problem
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. :)
Re: QTreeWidget, resizing item and widgets problem
What does the embedded widget consist of?
Re: QTreeWidget, resizing item and widgets problem
The base is QFrame, on that frame there is 3-4 QLabels with CSS styling, thats all. :)
Re: QTreeWidget, resizing item and widgets problem
Did the embedded widget changed its size ever when you resized the tree widget?
Re: QTreeWidget, resizing item and widgets problem
Quote:
Originally Posted by
The Storm
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.
Re: QTreeWidget, resizing item and widgets problem
@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... :(
Re: QTreeWidget, resizing item and widgets problem
Quote:
Originally Posted by
The Storm
@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.
Quote:
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.
1 Attachment(s)
Re: QTreeWidget, resizing item and widgets problem
Quote:
Originally Posted by
wysota
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.
Re: QTreeWidget, resizing item and widgets problem
Quote:
Originally Posted by
The Storm
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?
Quote:
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.
Re: QTreeWidget, resizing item and widgets problem
Here's the code
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. :)
Re: QTreeWidget, resizing item and widgets problem
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?
Re: QTreeWidget, resizing item and widgets problem
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. :)
Code:
class ContactWidget
: public QFrame{
Q_OBJECT
public:
~ContactWidget() {};
};
Re: QTreeWidget, resizing item and widgets problem
Quote:
Originally Posted by
The Storm
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)?
Re: QTreeWidget, resizing item and widgets problem
It's flat structure, there is no childs. :)
Re: QTreeWidget, resizing item and widgets problem
Could you just for testing issue such code and show us the result?
Code:
selectedItem->setData(Qt::blue, Qt::BackgroundRole);
Re: QTreeWidget, resizing item and widgets problem
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. :)