I changed the code so but it doesn't work well:
{
public:
{
//palette.setBrush( QPalette::WindowText, QBrush( Qt::red ) );
setPalette(palette);
}
protected:
{
QPen pen
( Qt
::blue,
1 );
// blue solid line, 1 pixels wide painter.setPen( pen );
// QStyleOptionFocusRect option;
// option.initFrom( this );
painter.setOpacity( 0.3 );
// painter.drawControl(QStyle::CE_FocusFrame, option);
painter.drawRect( rect );
}
};
class WfRubberBand : public QRubberBand
{
public:
WfRubberBand( Shape s, QWidget * p = 0 ) : QRubberBand( s, p )
{
QPalette palette;
//palette.setBrush( QPalette::WindowText, QBrush( Qt::red ) );
palette.setBrush( QPalette::Foreground, QBrush( Qt::red ) );
setPalette(palette);
}
protected:
virtual void paintEvent( QPaintEvent *pe )
{
QStylePainter painter( this );
QRect rect = pe->rect();
QPen pen( Qt::blue, 1 ); // blue solid line, 1 pixels wide
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?
Bookmarks