PDA

View Full Version : QPainter clipped?



nikita
22nd September 2006, 00:38
hi,
i subclassed QPushButton for a widget i'm using and i'm having problems getting the whole button to show. when the button is drawn the "ends" are missing. i've tried changing the scale and translation with no luck. i have looked at the docs trying to figure which if i'm clipping by mistake in orientation. here's the code with no geometry set:

void pb: : paintEvent(QPaintEvent *)
{
QStyleOptionButton option;
option.initFrom(this);
QStylePainter p(this);
p.scale(1.0, 8.50);
p.translate(0,50);
p.rotate(-90);
p.drawControl(QStyle::CE_PushButton, option);
}


thanks in advance.

jpn
23rd September 2006, 09:22
A widget cannot draw outside it's boundaries.

Since you rotate 90 degrees, you must also swap the width and height:


QSize s = option.rect.size(); // rect has been initialized in QStyleOption::initFrom()
s.transpose(); // swaps width and height
option.rect.setSize(s);


..and you must translate the coordinate system to match rotation


p.rotate(-90);
p.translate(-height(), 0);


You might also want to take a look at QPushButtonPrivate::getStyleOption(). You need a properly initialized QStyleOptionButton to get the button drawn correctly.

jpn
24th September 2006, 13:29
QtCentre Wiki: OrientationButton (http://wiki.qtcentre.org/index.php?title=OrientationButton)