Hope it does nowQuote:
Originally Posted by aamer4yu View Post
Try this -
painter.setOpacity(0.5)... in the paintEvent
It doesn't work.![]()
Hope it does nowQuote:
Originally Posted by aamer4yu View Post
Try this -
painter.setOpacity(0.5)... in the paintEvent
It doesn't work.![]()
Come on, that's not a big deal, it like you set the opacity. And since you obviously don't need a style aware rubber band, get rid of that QStyleOptionFocusRect stuff and draw that rubber rect yourself using QPainter::drawRect(). This will also increase your speed.
I changed the code so but it doesn't work well:
Qt Code:
{ public: { QPalette palette; //palette.setBrush( QPalette::WindowText, QBrush( Qt::red ) ); setPalette(palette); } protected: { painter.setPen( pen ); // QStyleOptionFocusRect option; // option.initFrom( this ); painter.setOpacity( 0.3 ); // painter.drawControl(QStyle::CE_FocusFrame, option); painter.drawRect( rect ); } };To copy to clipboard, switch view to plain text mode
The rect is not filled with the red color, but it's empty.
Where my code is wrong?
Franco Amato
Use QPainter instead of QStylePainter since you don't use it's possibilities. And then use QPainter::setBrush() to define the fill color.
Hi
just for those not wanting to re-implement a paint event for changing colors:
callingon a QRubberBand changes the background color of the selected area to yellow as expected.Qt Code:
setStyleSheet("selection-background-color: yellow");To copy to clipboard, switch view to plain text mode
Hope this will help someone.
Clément.
mvuori (4th August 2011)
Bookmarks