Results 1 to 4 of 4

Thread: QTreeView: How to center a checkbox in a cell

  1. #1
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default QTreeView: How to center a checkbox in a cell

    I have a QTreeView with a custom model. In that model I display boolean types with a checkbox using the CheckStateRole. I have nothing in the DisplayRole which basically gives you a checkbox and nothing else in that cell. Does anyone have a good idea of how to get that checkbox to be center aligned in the cell?

    Unfortunately the Qt::TextAlignmentRole doesnt affect the checkbox. I suppose its possible to use a proxy style but I have no clue how to correctly implement it. Any ideas? Code?

  2. #2
    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: QTreeView: How to center a checkbox in a cell

    QItemDelegate::createEditor might help you.

    Also search the forums, ther have been threads on similar situations

  3. #3
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView: How to center a checkbox in a cell

    Quote Originally Posted by aamer4yu View Post
    QItemDelegate::createEditor might help you.

    Also search the forums, ther have been threads on similar situations
    I think use QItemDelegate::createEditor is not a convenient way. I search the forums , and get nothing could help. Can you make it more clearly? Thanks in advance!
    Jerry

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView: How to center a checkbox in a cell

    you can override
    Qt Code:
    1. virtual void QItemDelegate::drawCheck ( QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect, Qt::CheckState state ) const
    To copy to clipboard, switch view to plain text mode 
    but click on this checkbox remains on old position not, on the center.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Replies: 3
    Last Post: 1st April 2011, 05:58
  2. How to set StyleSheet for checkbox in QTreeView;
    By visor_ua in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2009, 12:46
  3. Center a widget in a cell on a QTableWidget
    By roleroz in forum Qt Programming
    Replies: 16
    Last Post: 5th March 2009, 15:47
  4. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 09:18
  5. qtreeview + checkboxes
    By lamera in forum Newbie
    Replies: 9
    Last Post: 6th September 2008, 23:10

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.