QPushButton Overlay Color
-
Well I basically was to make a QPushButton which has a color contained with in it, basically a box with a color overlapped on top of a button. When you press the button it'll open a QColorDialog which you than pick a color, setting the color overlapped on top of the button to the newly selected color. I'd prefer to not make a new control so I was wondering if there is a way to do this.
-
-
In your reimplementation, you forgot to include a call to the base class implementation. The code above will only draw the square.
@
void ColorButton::paintEvent( QPaintEvent* event )
{
QPushButton::paintEvent(event); // <-- do not forget this lineQPainter painter( this ); painter.setBrush( QBrush( currentColor_ ) ); painter.drawRect( event->rect() );
}
@You might also considder just creating a pixmap, and setting that on the button with setPixmap if the color changes. You can do that either in a subclass or separately from the button code.