Results 1 to 3 of 3

Thread: Painting a CC_ToolButton in a custom delegate

  1. #1
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Painting a CC_ToolButton in a custom delegate

    I have a read-only model providing a contact list and a custom delegate to paint the contacts' details as well as two buttons. I also subclassed the view to be able to get mouse move and press events. Thus, the buttons can be clicked and react to mouse over events although they are just painted in the paint() method of the delegate. They are working fine but now I want to use toolbuttons instead, since one of them will have to be able to display a drop-down popup menu. This is the relevant part of paint() in the custom delegate:

    Qt Code:
    1. // Draw buttons
    2. QStyleOptionToolButton callOptionButton;
    3. callOptionButton.direction = qApp->layoutDirection();
    4. callOptionButton.features = QStyleOptionToolButton::MenuButtonPopup;
    5. callOptionButton.palette = qApp->palette();
    6. callOptionButton.rect = callButtonRect(option.rect);
    7. callOptionButton.state = QStyle::State_Enabled | QStyle::State_Raised;
    8. callOptionButton.toolButtonStyle = Qt::ToolButtonIconOnly;
    9. if(m_activeOnIndex == index && m_activeButton == CallButton) {
    10. if(m_isActiveButtonHovered) {
    11. callOptionButton.state &= ~QStyle::State_Raised;
    12. callOptionButton.state |= QStyle::State_Sunken;
    13. }
    14. } else if(m_pointerOnIndex == index && m_hoveredButton == CallButton)
    15. callOptionButton.state |= QStyle::State_MouseOver;
    16. callOptionButton.icon = QIcon(":/images/22x22/apps/internet-telephony.png");
    17. callOptionButton.iconSize = QSize(22, 22);
    18. qApp->style()->drawComplexControl(QStyle::CC_ToolButton, &callOptionButton, painter, m_view);
    19.  
    20. if(!email.isEmpty()) {
    21. QStyleOptionToolButton emailOptionButton;
    22. emailOptionButton.arrowType = Qt::NoArrow;
    23. emailOptionButton.direction = qApp->layoutDirection();
    24. emailOptionButton.features = QStyleOptionToolButton::None;
    25. emailOptionButton.palette = qApp->palette();
    26. emailOptionButton.rect = emailButtonRect(option.rect);
    27. emailOptionButton.state = QStyle::State_Enabled | QStyle::State_Raised;
    28. emailOptionButton.toolButtonStyle = Qt::ToolButtonIconOnly;
    29. if(m_activeOnIndex == index && m_activeButton == EmailButton) {
    30. if(m_isActiveButtonHovered) {
    31. emailOptionButton.state &= ~QStyle::State_Raised;
    32. emailOptionButton.state |= QStyle::State_Sunken;
    33. }
    34. } else if(m_pointerOnIndex == index && m_hoveredButton == EmailButton)
    35. emailOptionButton.state |= QStyle::State_MouseOver;
    36. emailOptionButton.icon = QIcon(":/images/22x22/actions/mail-message-new.png");
    37. emailOptionButton.iconSize = QSize(22, 22);
    38. qApp->style()->drawComplexControl(QStyle::CC_ToolButton, &emailOptionButton, painter, m_view);
    39. }
    To copy to clipboard, switch view to plain text mode 

    The problem is they don't look as they should. With the Oxygen style (1st attachment), the phone toolbuttons look like if they had QStyle::State_AutoRaise set while it isn't. With the Plastique style (2nd attachment), they look fine but the E-mail tool buttons are painted with an arrow icon instead of the mail icon, like if QStyleOptionToolButton::arrowType was Qt:: DownArrow. Any idea why this happens? Is there, perhaps, a better way to have tool buttons for every row in the view?

    PS: The 3rd attachment is how I'd like them to look like.
    Attached Images Attached Images

  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: Painting a CC_ToolButton in a custom delegate

    The best way to debug these kind of issues is to step line by line through the style drawing code to see exactly what happens.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting a CC_ToolButton in a custom delegate

    I got an answer from the Trolltech technical support, so I post the solution here. I Just needed to add this:

    Qt Code:
    1. emailOptionButton.subControls = QStyle::SC_ToolButton;
    To copy to clipboard, switch view to plain text mode 

    That way only the ToolButton subcontrol is painted but the arrow subcontrol isn't. I personally find it a bit weird having to do it this way while I already set Qt::NoArrow but it works.

Similar Threads

  1. Save problem with custom delegate
    By Banjo in forum Qt Programming
    Replies: 0
    Last Post: 22nd July 2008, 02:34
  2. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  3. QMovie from inside a custom item delegate
    By Crazy_Hopper in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2008, 15:18
  4. Capture events in a custom delegate
    By vfernandez in forum Qt Programming
    Replies: 9
    Last Post: 19th March 2008, 05:33
  5. updating database with custom delegate
    By Shaitan in forum Qt Programming
    Replies: 4
    Last Post: 17th July 2007, 10:34

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.