Results 1 to 3 of 3

Thread: Paint XP radio button to pixmap

  1. #1
    Join Date
    Feb 2006
    Posts
    21
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Paint XP radio button to pixmap

    Hi,

    I'm trying to grab the pixmap for a radio button from the QWindowsXPStyle. I thought that using the style to paint a radio button into a pixmap would work, but I keep getting an empty white square. Any ideas what I'm doing wrong? Here's a code snippet:
    Qt Code:
    1. QWindowsXPStyle oBaseStyle;
    2. QRadioButton oRadioButton;
    3. QStyleOption oRadioStyleOption;
    4. QSize oNormalRadioSize;
    5. oRadioButton.setStyle(&oBaseStyle);
    6. oRadioButton.ensurePolished();
    7. oRadioStyleOption.initFrom(&oRadioButton);
    8. oNormalRadioSize.setWidth(QWindowsXPStyle::pixelMetric(PM_ExclusiveIndicatorWidth, &oRadioStyleOption, &oRadioButton));
    9. oNormalRadioSize.setHeight(QWindowsXPStyle::pixelMetric(PM_ExclusiveIndicatorHeight, &oRadioStyleOption, &oRadioButton));
    10.  
    11.  
    12. // Initialize a painter and pixmap for drawing the radio buttons
    13. // at their normal sizes.
    14. QPixmap oRadioPixmap(oNormalRadioSize);
    15. QPainter oRadioPainter;
    16. oRadioPainter.setBackgroundMode(Qt::TransparentMode);
    17.  
    18. // Draw the radio button into the pixmap.
    19. oRadioPainter.begin(&oRadioPixmap);
    20. oRadioButton.setChecked(true);
    21. oRadioButton.setEnabled(true);
    22. QWindowsXPStyle::drawPrimitive(PE_IndicatorRadioButton, &oRadioStyleOption, &oRadioPainter, &oRadioButton);
    23. oRadioPainter.end();
    To copy to clipboard, switch view to plain text mode 

  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: Paint XP radio button to pixmap

    QStyleOption oRadioStyleOption.rect is not initialized correctly because the radio button is not visible and therefore does not supply a valid geometry for the style option.
    J-P Nurmi

  3. #3
    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: Paint XP radio button to pixmap

    Try adding this somewhere before calling drawPrimitive():
    Qt Code:
    1. oRadioStyleOption.rect = QRect(QPoint(0,0), oNormalRadioSize);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. QPainter::begin: Cannot paint on a null pixmap
    By sabeesh in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2010, 18:03
  2. Radio buttons in a tree view
    By notwithstanding in forum Qt Programming
    Replies: 6
    Last Post: 3rd November 2008, 22:32
  3. Coloring of Radio Button
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 22nd July 2008, 15:05
  4. Undoing radio button checks.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2007, 09:12
  5. How to paint a selection rectangle on a pixmap?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 8th January 2006, 19:52

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.