Results 1 to 6 of 6

Thread: QListWidget resize item to reproduce Windows behavior : Magical Number needed

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QListWidget resize item to reproduce Windows behavior : Magical Number needed

    The magic is likely some element(s) of the style's rendering of the widgets that you are not accounting for. You may be able to work the amount of "magic" required using the QStyle::pixelMetric() function and constants
    http://doc.qt.io/qt-4.8/qstyle.html#PixelMetric-enum

    The flickering is probably because the automatic scrollbar is being added and removed repeatedly because the size of the contained widget is changing around the scroll area's critical size. You need to be careful that the appearance of the scroll bar, which narrows the viewport, does not trigger a shrinking of the layout that causes the viewport to grow... Circular updates.

  2. #2
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListWidget resize item to reproduce Windows behavior : Magical Number needed

    The idea is easy, simply compensate the empty space on each item to use the whole space on the width but to remove this constant, it's not so easy.
    Using a little value to only have very little empty space you got bad result (flickering). The solution I give is the only one I found after lot of tests.
    Maybe a padding-left needed to solve completely, but then you have big margin on the left and right of the row.
    using :
    Qt Code:
    1. m_ListWidget->setStyleSheet( "QListView{ padding-left: 10px; }" );
    To copy to clipboard, switch view to plain text mode 
    I have to use this value to have 0 flickering (if the scrollbar is visible or not) :
    Qt Code:
    1. const int RightMargin = 28;
    To copy to clipboard, switch view to plain text mode 
    But the margin is not the same on the left and right, I have 10px on the left but more space on the right, 28px.
    For the case where no padding-left is set, I got also good visual without flickering using 18px for the RightMargin, which gives less empty space than 20px.
    That works very well but it's not centered, you have 0 empty space on the left and 18px empty space on the right and no solution found to have it centered...
    Last edited by Alundra; 19th January 2016 at 01:01.

Similar Threads

  1. Dynamically resize item of QListWidget
    By Alundra in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2016, 22:20
  2. Replies: 1
    Last Post: 11th November 2015, 13:14
  3. QSplitter resize behavior
    By Alundra in forum Qt Programming
    Replies: 0
    Last Post: 5th June 2014, 21:25
  4. Strange resize behavior
    By Lykurg in forum Newbie
    Replies: 3
    Last Post: 9th January 2007, 13:56
  5. QListWidget selection behavior as in Windows XP
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2007, 13:11

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
  •  
Qt is a trademark of The Qt Company.