PDA

View Full Version : Border-image not working in QWidget?



astampor
30th September 2011, 19:19
I have a class derived from QWidget. When I try to use the style-sheet to set the border-image, it appears to ignore it. I am using QT 4.4 and it looks like the QWidget should support border-image. Is there something I would need to do in the paint event to get it to display, or something else I am missing?

Also, is it possible to define a series of images for the border, using border-top-left-image and the rest?

wysota
1st October 2011, 19:50
Is there something I would need to do in the paint event to get it to display, or something else I am missing?
Yes. You need to use QStyle API to render the PE_Widget primitive.

Jonny174
3rd October 2011, 03:24
See this: http://doc.crossplatform.ru/qt/4.6.x/stylesheet-examples.html#qpushbutton-and-images

astampor
3rd October 2011, 15:01
Yes. You need to use QStyle API to render the PE_Widget primitive.

In the paintEvent, I am already doing this:


QPainter painter(this);
QStyleOption o;
o.initFrom(this);
style()->drawPrimitive(QStyle::PE_Widget, &o, &painter, this);


I needed this to get the background image to draw. Is there something else I need to add to get the border-image to draw as well?

wysota
3rd October 2011, 15:16
No, this should be sufficient. It could be that you can't use both the background and border image or that you are doing something else incorrectly. Does it work if you apply both the background and the border image to a plain QWidget instance?