Results 1 to 6 of 6

Thread: Determining the height of an item in a QListWidget

  1. #1
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Determining the height of an item in a QListWidget

    How can I determine the height of a single item in a QListWidget? I'm looking for the equivalent of Q3ListBox::itemHeight, or MFC's CListBox::GetItemHeight:

    http://msdn.microsoft.com/en-us/library/d5804hcf.aspx

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Determining the height of an item in a QListWidget

    Using visualRect you can determine the height.

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Determining the height of an item in a QListWidget

    or you can directly go for QListWidget::visualItemRect(QListWidgetItem);

  4. #4
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Determining the height of an item in a QListWidget

    Thanks guys! QListWidget::visualItemRect worked, but the more generic QAbstractItemView::visualRect returned a height of zero. I'm not sure why there's a discrepancy.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Determining the height of an item in a QListWidget

    How did you call QAbstractItemView::visualRect ???

  6. #6
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Determining the height of an item in a QListWidget

    Now that I try it again, it works.

    Qt Code:
    1. QRect itemRect1 = listWidget.visualItemRect(listWidget.item(0));
    2. QRect itemRect2 = listWidget.visualRect(listWidget.model()->index(0, 0));
    To copy to clipboard, switch view to plain text mode 
    At the end itemRect1 == itemRect2;

Similar Threads

  1. Help on QListWidget InternalMove item signal
    By tho97 in forum Qt Programming
    Replies: 3
    Last Post: 14th February 2009, 02:13
  2. QListWidget and selecting an item
    By invictus in forum Newbie
    Replies: 4
    Last Post: 19th June 2007, 12:59
  3. Replies: 1
    Last Post: 19th April 2007, 23:23
  4. extract item from QListWidget
    By impeteperry in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 20:41
  5. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 10: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.