Results 1 to 16 of 16

Thread: QTreeWidget, resizing item and widgets problem

  1. #1
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget, resizing item and widgets problem

    What does the embedded widget consist of?

  3. #3
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget, resizing item and widgets problem

    The base is QFrame, on that frame there is 3-4 QLabels with CSS styling, thats all.

  4. #4
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeWidget, resizing item and widgets problem

    Did the embedded widget changed its size ever when you resized the tree widget?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget, resizing item and widgets problem

    Quote Originally Posted by The Storm View Post
    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.

  6. #6
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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...

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget, resizing item and widgets problem

    Quote Originally Posted by The Storm View Post
    @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.

  8. #8
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget, resizing item and widgets problem

    Quote Originally Posted by wysota View Post
    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.
    Attached Images Attached Images

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget, resizing item and widgets problem

    Quote Originally Posted by The Storm View Post
    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.

  10. #10
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget, resizing item and widgets problem

    Here's the code
    Qt Code:
    1. ContactWidget *pContactWidget = new ContactWidget();
    2. pContactWidget->setAutoFillBackground(true);
    3. /* Setting some data to the QLabels inside the pContactWidget */
    4. pContactView->setItemWidget(selectedItem, 0, pContactWidget);
    To copy to clipboard, switch view to plain text mode 

    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.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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?

  12. #12
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.
    Qt Code:
    1. class ContactWidget : public QFrame
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ContactWidget(QWidget *parent = 0) : QFrame(parent) {};
    7. ~ContactWidget() {};
    8. };
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget, resizing item and widgets problem

    Quote Originally Posted by The Storm View Post
    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)?

  14. #14
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget, resizing item and widgets problem

    It's flat structure, there is no childs.

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget, resizing item and widgets problem

    Could you just for testing issue such code and show us the result?

    Qt Code:
    1. selectedItem->setData(Qt::blue, Qt::BackgroundRole);
    To copy to clipboard, switch view to plain text mode 

  16. #16
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

Similar Threads

  1. QTreeWidget's Item Widgets
    By jpn in forum Qt Programming
    Replies: 11
    Last Post: 1st April 2006, 23:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.