Results 1 to 6 of 6

Thread: ListWidget -> custom Item -> height

  1. #1
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default ListWidget -> custom Item -> height

    So mine question is: is there any way to make listWidgetItem occupy as much space as it needs (apposed to fixed size)? I use customised widget as items (2 labels + picture + Multi-line lable).

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ListWidget -> custom Item -> height

    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ListWidget -> custom Item -> height

    Quote Originally Posted by mcosta View Post
    Unfortunately i don't know how much space will item occupy... As i said earlier, it contains 2 labels, image and multiline lable, which can be sized from 1 to 15 lines. How do I use setSizeHint in this situation?

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ListWidget -> custom Item -> height

    Quote Originally Posted by Archa4 View Post
    Unfortunately i don't know how much space will item occupy... As i said earlier, it contains 2 labels, image and multiline lable, which can be sized from 1 to 15 lines. How do I use setSizeHint in this situation?
    You have to compute tha maximum size hint of single components.
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ListWidget -> custom Item -> height

    Quote Originally Posted by mcosta View Post
    You have to compute tha maximum size hint of single components.
    Well.. the maximum size of hints is the same... I tried to compine their heights using, for example:
    name = new QLabel("Name");
    int asd;
    asd += int->height();
    but all the labels have the same height, so i cannot define which items should be bigger, and which should be smaller...

  6. #6
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ListWidget -> custom Item -> height

    The size hint is computed by widget and depends on their content.

    This code works
    Qt Code:
    1. void Widget::on_computeButton_clicked()
    2. {
    3. int maximumSizeHint = 0;
    4.  
    5. QList<QLabel*> labels = this->findChildren <QLabel*> ();
    6. Q_FOREACH (QLabel* lab, labels) {
    7. int itemp = lab->sizeHint ().height ();
    8.  
    9. qDebug ("%s sizeHint.height = %d", qPrintable(lab->objectName ()), itemp);
    10. if (itemp > maximumSizeHint)
    11. maximumSizeHint = itemp;
    12. }
    13.  
    14. qDebug ("Maximum sizeHint height = %d", maximumSizeHint);
    15. }
    To copy to clipboard, switch view to plain text mode 

    The output is:
    Qt Code:
    1. label sizeHint.height = 13
    2. label_2 sizeHint.height = 13
    3. label_3 sizeHint.height = 39
    4. Maximum sizeHint height = 39
    To copy to clipboard, switch view to plain text mode 

    The widget is in attachment:image.PNG
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. Replies: 2
    Last Post: 3rd February 2011, 10:07
  2. Check if item exists into listwidget
    By hakermania in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2011, 21:54
  3. ListWidget item's height
    By BalaQT in forum Qt Programming
    Replies: 1
    Last Post: 12th July 2010, 13:51
  4. Replies: 1
    Last Post: 16th May 2010, 23:40
  5. ListWidget positions item
    By talex in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2008, 15:16

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.