PDA

View Full Version : Paint XP radio button to pixmap



Ben.Hines
26th April 2006, 14:47
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:


QWindowsXPStyle oBaseStyle;
QRadioButton oRadioButton;
QStyleOption oRadioStyleOption;
QSize oNormalRadioSize;
oRadioButton.setStyle(&oBaseStyle);
oRadioButton.ensurePolished();
oRadioStyleOption.initFrom(&oRadioButton);
oNormalRadioSize.setWidth(QWindowsXPStyle::pixelMe tric(PM_ExclusiveIndicatorWidth, &oRadioStyleOption, &oRadioButton));
oNormalRadioSize.setHeight(QWindowsXPStyle::pixelM etric(PM_ExclusiveIndicatorHeight, &oRadioStyleOption, &oRadioButton));


// Initialize a painter and pixmap for drawing the radio buttons
// at their normal sizes.
QPixmap oRadioPixmap(oNormalRadioSize);
QPainter oRadioPainter;
oRadioPainter.setBackgroundMode(Qt::TransparentMod e);

// Draw the radio button into the pixmap.
oRadioPainter.begin(&oRadioPixmap);
oRadioButton.setChecked(true);
oRadioButton.setEnabled(true);
QWindowsXPStyle::drawPrimitive(PE_IndicatorRadioBu tton, &oRadioStyleOption, &oRadioPainter, &oRadioButton);
oRadioPainter.end();

jpn
26th April 2006, 20:26
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.

jpn
26th April 2006, 21:15
Try adding this somewhere before calling drawPrimitive():


oRadioStyleOption.rect = QRect(QPoint(0,0), oNormalRadioSize);