Results 1 to 2 of 2

Thread: Drawing a Checkbox Checkmark primitive with colored background

  1. #1
    Join Date
    Apr 2019
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Question Drawing a Checkbox Checkmark primitive with colored background

    Hi,

    title says it all, I want to draw the checkmark with a colored background in the paint function of a custom delegate derived from QSytledItemDelegate. So far I tried

    Qt Code:
    1. QStyleOptionFocusRect focusrectOption;
    2. focusrectOption.rect = layerRect;
    3. focusrectOption.backgroundColor = QColor(151,165,255);
    4.  
    5. QApplication::style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &focusrectOption, painter);
    To copy to clipboard, switch view to plain text mode 

    and giving the QPainter a background color

    Qt Code:
    1. painter->setBackground(QBrush(QColor(151,165,255)));
    2. QApplication::style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &checkBoxOption, painter);
    To copy to clipboard, switch view to plain text mode 

    but it just doesnt draw anything. Any idea how to achieve this without having to draw the checkmark myself with lines?

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    487
    Thanks
    11
    Thanked 71 Times in 69 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Drawing a Checkbox Checkmark primitive with colored background

    Hi, do you have correct values for the .rect entries in the QStyleOption subclasses? Please check if focusrectOption.rect is non-zero after this line:
    focusrectOption.rect = layerRect;
    You probably have a similar line for checkBoxOption.

    Ginsengelf

Similar Threads

  1. Drawing background while mouseMoving
    By Caolan O'Domhnaill in forum Newbie
    Replies: 8
    Last Post: 8th July 2016, 20:12
  2. Replies: 0
    Last Post: 30th April 2014, 14:08
  3. Replies: 0
    Last Post: 5th April 2011, 13:36
  4. Drawing background of a scene
    By maverick_pol in forum Qt Programming
    Replies: 0
    Last Post: 11th January 2008, 11:12
  5. Drawing the background of QGraphicsView
    By aknuds1 in forum Qt Programming
    Replies: 13
    Last Post: 9th March 2007, 14:53

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.