Results 1 to 2 of 2

Thread: Customizing the checkboxes of the items of a QTreeView

  1. #1
    Join Date
    Oct 2011
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Customizing the checkboxes of the items of a QTreeView

    Hello.

    I'm having the following situation: I need to create a custom tree control, whose checkboxes are also customized. I have easily made most of the customizations for the tree control by using style sheets; I have succeeded adding checkboxes to the QTreeView's items, but I'm having big problems with customizing them - I need to display a custom image for the checked state, and another for the unchecked state.

    The place I concluded this can be done is in my subclass of QStyledItemDelegate, in the paint event (i.e. CheckBoxItemDelegate::paint). What I need is to display the text, the icon, and the checkbox for the item. But the problems are:
    - I can't get the style of the item (which I set using the stylesheet) - otherwise my text can be drawn with the incorrect color;
    - I don't know the rects of each subitem (the checkbox, the icon, the text);
    - I don't know how to get the icon of an item (given its QModelIndex) to draw it.

    P.S. I had subclassed the QTreeView (obviously), and, as I am working with QFileSystemModel, I have subclassed it too in order to add the checkbox functionality to it.

    Can anybody help me, please?
    Is QStyledItemDelegate::paint the proper place for changing the visuals of the checkbox of the tree items? If yes, can you please give me a small example or something, how I can do that?
    Last edited by Feoggou; 22nd March 2012 at 17:13.

  2. #2
    Join Date
    Oct 2011
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Customizing the checkboxes of the items of a QTreeView

    I have found that the answer is this:

    Qt Code:
    1. ui.myTreeView->setStyleSheet(
    2. "QTreeView::indicator:unchecked {image: url(:/icons/eye_grey.png);}"
    3. "QTreeView::indicator:checked {image: url(:/icons/eye.png);}"
    4. );
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Feoggou for this useful post:

    rexocool (13th January 2013)

Similar Threads

  1. Replies: 1
    Last Post: 6th May 2011, 13:17
  2. QTreeView and CheckBoxes
    By FreeG in forum Qt Programming
    Replies: 2
    Last Post: 9th December 2009, 09:36
  3. qtreeview + checkboxes
    By lamera in forum Newbie
    Replies: 9
    Last Post: 6th September 2008, 22:10
  4. Checkboxes in menu items
    By markcole in forum Qt Programming
    Replies: 2
    Last Post: 4th June 2007, 15:16
  5. QTreeView with checkboxes
    By shad in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2006, 13:29

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.