Trying to Draw QRubberBand but QRubberBand not displayed properly
-
wrote on 25 May 2017, 13:12 last edited by
-
wrote on 25 May 2017, 13:23 last edited by
Hi,
Could you show your code that sets the color to Yellow?
Eddy
-
wrote on 26 May 2017, 04:35 last edited by
the following is the code i am using
dummyband = new QRubberBand(QRubberBand::Rectangle, this);
QPalette palette; //palette.setBrush(QPalette::Foreground, QBrush(color)); //palette.setBrush(QPalette::Base, QBrush(color)); palette.setBrush(QPalette::Highlight, QBrush(yellow)); dummyband->setPalette(palette); dummyband->setGeometry(QRect(topLeft, bottomRight)); dummyband->show();
-
Hi
The docs saysRectangle A QRubberBand can represent a rectangle. Some
styles will interpret this as a filled (often
semi-transparent) rectangle, or a rectangular
outline.It's also filled on windows 10 so I guess it's by design / also affected by the platform style.
It draws with QStyle::CE_RubberBand
so you could override with http://doc.qt.io/qt-5/qproxystyle.htmlclass MRubberStyle : public QProxyStyle { public: MRubberStyle() : QProxyStyle() {} ~MRubberStyle() {} virtual void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = 0) const { switch(element) { case CE_RubberBand: // draw as u want return; default: QApplication::style()->drawControl(element, option, painter, widget); } } }; ... app.setStyle( new MRubberStyle );
-
wrote on 26 May 2017, 05:17 last edited by
You should not use setBrush, it will fill your rectangle with yellow color, Use setPen with yellow color, it will set the yellow border.
-
You should not use setBrush, it will fill your rectangle with yellow color, Use setPen with yellow color, it will set the yellow border.
wrote on 26 May 2017, 05:48 last edited bynot getting setPen in QPalette
-
wrote on 26 May 2017, 05:57 last edited by
@Swapnil_Shelke ,
OK. try this,
rubberBand->setPalette(Qt::transparent); -
@Swapnil_Shelke ,
OK. try this,
rubberBand->setPalette(Qt::transparent);wrote on 26 May 2017, 09:00 last edited byNo not working ,
rubberBand->setPalette(Qt::transparent); removes the color from borders also..
8/8