Results 1 to 4 of 4

Thread: Another delegate problem...

  1. #1
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Another delegate problem...

    I made (with numbat's help) a delegate for drawing items in a qtreeview. But now I have another problem with the delegate.



    Do you see the border line (1px) that is a little bit darker than the color around it? It should be drawn at the very left part of the item. Instead of that the delegate draws the item (at the right) and some kind of square (at the left).

    And if I set border-radius (rounded borders) in the stylesheet, I get rounded borders on the item and on the square.

    How can I make it draw everything as just one item?

    Delegate code:

    Qt Code:
    1. def paint(self, painter, option, index):
    2. if not index.isValid():
    3. return
    4. options = QStyleOptionViewItemV4(option)
    5. self.initStyleOption(options, index)
    6. painter.save()
    7. painter.setRenderHint(QPainter.Antialiasing, True)
    8. doc = QTextDocument()
    9. doc.setHtml(options.text)
    10. options.text = ""
    11. options.widget.style().drawControl(QStyle.CE_ItemViewItem, options, painter, options.widget)
    12. painter.translate(options.rect.left(), options.rect.top())
    13. rect = QRectF(0, 0, options.rect.width(), options.rect.height())
    14. doc.drawContents(painter, rect)
    15. painter.restore()
    To copy to clipboard, switch view to plain text mode 

    Thanks

  2. #2
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Another delegate problem...

    Thinking about it better, it would be better if I could remove that strange square.
    Does somebody know how to remove it?

  3. #3
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Another delegate problem...

    I solved it. It's because of the branch's. If somebody is having the same problem, here is the stylesheet that will remove the square:

    Qt Code:
    1. QTreeView::branch {
    2. background: white;
    3. }
    4.  
    5. QTreeView::branch:has-siblings:!adjoins-item {
    6. background: white;
    7. border-image: none;
    8. image: none;
    9. }
    10.  
    11. QTreeView::branch:has-siblings:adjoins-item {
    12. background: white;
    13. border-image: none;
    14. image: none;
    15. }
    16.  
    17. QTreeView::branch:!has-children:!has-siblings:adjoins-item {
    18. background: white;
    19. border-image: none;
    20. image: none;
    21. }
    22.  
    23.  
    24. QTreeView::branch:has-children:!has-siblings:closed,
    25. QTreeView::branch:closed:has-children:has-siblings {
    26. background: white;
    27. border-image: none;
    28. }
    29.  
    30. QTreeView::branch:open:has-children:!has-siblings,
    31. QTreeView::branch:open:has-children:has-siblings {
    32. background: white;
    33. border-image: none;
    34. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Another delegate problem...

    You also could check the index inside your paint method if it is a branch and then remove the QStyle::State_Selected from the option.

Similar Threads

  1. problem with opengl, zooming, drawpixels, and origin
    By ntp in forum General Programming
    Replies: 0
    Last Post: 22nd February 2008, 21:48
  2. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  3. Delegate editor sizing problem
    By smacchia in forum Qt Programming
    Replies: 19
    Last Post: 7th December 2007, 16:27
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

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.