Results 1 to 5 of 5

Thread: QTreeWidgetItem - widget with layout collapsing

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTreeWidgetItem - widget with layout collapsing

    Hello! I have troubles with creating userlist in my IM. Because I need to display some data in one Item. I decided to embed QFrame into widget, make layout and insert labels into that layout. Here is code of my function used to create item (pointer is returned, needed by userlist manager)

    Qt Code:
    1. QTreeWidgetItem* QTlenRosterBox::addRosterItem(QString name,
    2. QTlenPresence type,
    3. QString desc,
    4. QString jid,
    5. QPixmap pxAvatar,
    6. {
    7. QTreeWidgetItem* item = new QTreeWidgetItem(node);
    8. QFrame* frame = new QFrame(this);
    9. QHBoxLayout* hLayout = new QHBoxLayout(frame);
    10. hLayout->setAlignment(Qt::AlignTop);
    11. QVBoxLayout* vLayout = new QVBoxLayout();
    12. vLayout->setAlignment(Qt::AlignTop);
    13. QLabel* statusIcon = new QLabel(frame);
    14. statusIcon->setFixedSize(16,16);
    15. switch (type)
    16. {
    17. case Online:
    18. statusIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/16x16/online.png")));
    19. break;
    20. case Chatty:
    21. statusIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/16x16/chatty.png")));
    22. break;
    23. case Away:
    24. statusIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/16x16/away.png")));
    25. break;
    26. case XA:
    27. statusIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/16x16/xa.png")));
    28. break;
    29. case DND:
    30. statusIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/16x16/dnd.png")));
    31. break;
    32. case Offline:
    33. statusIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/16x16/offline.png")));
    34. break;
    35. }
    36.  
    37. hLayout->addWidget(statusIcon);
    38. hLayout->addLayout(vLayout);
    39. QLabel* nameLabel = new QLabel(name, frame);
    40. QFont nameFont;
    41. nameFont.setBold(true);
    42. nameLabel->setFont(nameFont);
    43. vLayout->addWidget(nameLabel);
    44. if (!desc.isEmpty() && settings->value("/roster/show_descriptions", false).toBool())
    45. {
    46. QLabel* descLabel = new QLabel(desc, frame);
    47. QFont descFont;
    48. descFont.setPointSize(7);
    49. descFont.setItalic(true);
    50. descLabel->setWordWrap(true);
    51. descLabel->setFont(descFont);
    52. vLayout->addWidget(descLabel);
    53. }
    54. //prowizorka
    55. if(settings->value("/roster/show_avatars", false).toBool())
    56. {
    57. QLabel* avatar = new QLabel();
    58. if(pxAvatar.isNull())
    59. avatar->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/64x64/default_av.png")));
    60. else
    61. avatar->setPixmap(pxAvatar);
    62. avatar->setAlignment(Qt::AlignRight);
    63. hLayout->addWidget(avatar);
    64. }
    65. frame->setLayout(hLayout);
    66. setItemWidget(item, 0, frame);
    67. return item;
    68. }
    To copy to clipboard, switch view to plain text mode 

    and here is roster with only one item visible and with two visible; height is calculated properly, but layout is collapsed.

    how to fix that in best way?
    thanks in advance.
    Attached Images Attached Images
    Last edited by enkidu; 25th July 2009 at 19:53. Reason: user request

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. hiding a widget without rearrange layout
    By mastupristi in forum Newbie
    Replies: 1
    Last Post: 6th July 2009, 17:20
  3. Replies: 1
    Last Post: 14th May 2009, 22:00
  4. Resize widget force layout resizing
    By ^NyAw^ in forum Qt Programming
    Replies: 17
    Last Post: 11th February 2009, 11:27
  5. resizing events of a custom widget in a layout
    By Rooster in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2008, 10:52

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.