PDA

View Full Version : paintEvent method problem



zgulser
8th April 2010, 09:07
Hi,

The code below draws the push button but not draws the focus rect with the desired color..Is there something wrong?



102 void CustomizedButton::paintEvent(...)
103 {
104 QStyleOptionButton buttonOptions;
105 buttonOptions.init(this);
106 buttonOptions.features = QStyleOptionButton::None;
107 buttonOptions.rect = rect();
108 buttonOptions.palette = palette();
109 buttonOptions.state = (isDown() ? QStyle::State_Sunken : QStyle::State_Raised);
110 style()->drawPrimitive(QStyle::PE_PanelButtonBevel, &buttonOptions, p, this);
111
112
113
114
115
116 QStyleOptionFocusRect frectOptions;
117 frectOptions.init(this);
118 frectOptions.palette.setColor(QPalette::Window, Qt::red);
119 frectOptions.rect = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &buttonOptions, this);
120 if (hasFocus())
121 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &frectOptions, p, this);
122 }

zgulser
8th April 2010, 12:32
Still no ideas?

By the way if I do the following, it drows the border rect...



QPen pen;
pen.setStyle(Qt::SolidLine);
pen.setColor(Qt::red);
painter.setPen(pen);
QRectF recta = style()->subElementRect(QStyle::SE_PushButtonFocusRect,
&option,
this);
painter.drawRect(recta);