Hi,
I am using QRubberBand to zoom the scene when user clicks and drags a rectangle area. How can I set the QRubberBand to different color, such as red?
Thanks
Printable View
Hi,
I am using QRubberBand to zoom the scene when user clicks and drags a rectangle area. How can I set the QRubberBand to different color, such as red?
Thanks
Never mind, soloved!
Can you post the solution too :rolleyes:
You won't like it. Codes were developed in Linux, and after moved to Windows, I got rubber band filled with red, so now I have to use #ifdef... too bad...
Code:
{ public: QPalette palette; setPalette(palette); } protected: QStyleOptionFocusRect option; option.initFrom( this ); } }; { #ifdef Q_WS_WIN #else #endif return rubberBand; }
One question ...
why did you inherit ? you could have very well set the palette on the object of QRubberBand, isnt it ?
Hi,
As aamer pointed out, is there a way to draw QRubberBand object with another color without inheriting the QRubberBand?
I've tried to solve it using style sheet and palette but neither of them worked.
Hi,
Regarding the solution posted above, is it possible to make the rubberband dashed line also by using QPalette or something?
You may try subclassing QRubberBand and setting palette while drawing.
Hi,
That's what I exactly did..but I couldn't find to how to set "dashed line" for QPalette.
Check Qt::PenStyle.
QPainter::setPen
I did it as well in the paintEvent method of my rubberband class but it didn't make any difference. I guess QPalette overwrites QPainter or something.
May be if you show some code, or give compilable code we can see whats wrong
I love to..
Code:
class CustomRubberBand : QRubberBand { { QPalette palette; setPalette(palette); repaint(); } { QStyleOptionFocusRect option; option.initFrom(this); painter.begin(this); QPen pen; pen.setStyle(Qt::DashLine); pen.setWidth(2); painter.setPen(pen); } friend class MyGraphView; };
What if you simply draw a rectangle painter.drawRect(...)
instead of the painter.drawControl(QStyle::CE_FocusFrame, option);
??
Simply worked beautifully. Thanks