The simplest solution I can think of is this
PushButton
::PushButton( const QString & text,
const QColor & color,
QWidget * parent,
const char* name
) {
_color = color;
setText(text);
mCustomToolTip = 0;
setMouseTracking(true);
}
PushButton::PushButton( const QString & text, const QColor & color,
QWidget * parent, const char* name )
: QPushButton(parent, name)
{
_color = color;
setText(text);
mCustomToolTip = 0;
setMouseTracking(true);
}
To copy to clipboard, switch view to plain text mode
QColor& PushButton::getColor()
{
return _color;
}
QColor& PushButton::getColor()
{
return _color;
}
To copy to clipboard, switch view to plain text mode
Then in CustomToolTip you can have this
{
p.fillRect( rect(), Qt::transparent );
if( parentWidget() )
{
p.setBrush( ((PushButton*)parentWidget())->getColor() );
p.drawEllipse(rect());
p.drawText(rect(), Qt::AlignCenter, parentWidget()->name());
}
}
void CustomToolTip::paintEvent ( QPaintEvent * )
{
QPainter p(this);
p.fillRect( rect(), Qt::transparent );
if( parentWidget() )
{
p.setBrush( ((PushButton*)parentWidget())->getColor() );
p.drawEllipse(rect());
p.drawText(rect(), Qt::AlignCenter, parentWidget()->name());
}
}
To copy to clipboard, switch view to plain text mode
Hence there is no need for enterEvent and leaveEvent eventhandlers filters
Bookmarks