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:
Code:
oRadioButton.setStyle(&oBaseStyle);
oRadioButton.ensurePolished();
oRadioStyleOption.initFrom(&oRadioButton);
oNormalRadioSize.
setWidth(QWindowsXPStyle::pixelMetric(PM_ExclusiveIndicatorWidth,
&oRadioStyleOption,
&oRadioButton
));
oNormalRadioSize.
setHeight(QWindowsXPStyle::pixelMetric(PM_ExclusiveIndicatorHeight,
&oRadioStyleOption,
&oRadioButton
));
// Initialize a painter and pixmap for drawing the radio buttons
// at their normal sizes.
QPixmap oRadioPixmap
(oNormalRadioSize
);
oRadioPainter.setBackgroundMode(Qt::TransparentMode);
// Draw the radio button into the pixmap.
oRadioPainter.begin(&oRadioPixmap);
oRadioButton.setChecked(true);
oRadioButton.setEnabled(true);
QWindowsXPStyle::drawPrimitive(PE_IndicatorRadioButton,
&oRadioStyleOption,
&oRadioPainter,
&oRadioButton
);
oRadioPainter.end();
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.
Re: Paint XP radio button to pixmap
Try adding this somewhere before calling drawPrimitive():
Code:
oRadioStyleOption.
rect = QRect(QPoint(0,
0), oNormalRadioSize
);