Results 1 to 2 of 2

Thread: A reliable way to get the size of a checkbox indicator

  1. #1
    Join Date
    Jan 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question A reliable way to get the size of a checkbox indicator

    Hi,

    A little introduction to the problem: I'm using a QTreeView where one of the columns is editable and the data is presented as checkboxes which, on the one hand, should look like the native checkboxes of the particular OS, and, on the other, should be centered in the tree column. For this, I'm using a CheckBoxDelegate class, derived from QItemDelegate.

    To center the checkbox, I can either use the static QRect::alignedRect() or calculate the appropriate rectangle myself. In both cases however, a prerequisite is to know how big actually the checkbox is.

    Initially I thought that calling the QStyle::pixelMetric() function with QStyle::PM_IndicatorWidth and QStyle::PM_IndicatorHeight would give me the size of a normal checkbox. The problem is that on Linux, this function returns a width that is too narrow and the checkbox's right border is not visible, while the same code on Windows produces a perfect checkbox. I certainly don't like the thought of adding some magic number of extra pixels to the indicator width returned by pixelMetric.

    I'd appreciate any thoughts and/or suggestions.
    Last edited by jpn; 15th February 2008 at 20:56. Reason: disabled smilies

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: A reliable way to get the size of a checkbox indicator

    Perhaps you could use built-in checkable items and get them center aligned by using a [WIKI]proxy style[/WIKI] and reimplementing QStyle::subElementRect(SE_ViewItemCheckIndicator)?
    J-P Nurmi

Similar Threads

  1. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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.