Mouse Over Event on QPushButtons
Hi all:)
I am working on Qt4.1 on my Intel MAC , I m having 5 buttons on my MainWindow and each button is represented by different Icon(image), What I wanted do is when mouse pointer is over the button it is replaced by the text,
For this I Subclass QPushButton & Use enter and leave events functions ,Its also working but when mouse pointer entered the buttons it replaces the icon of everybutton with the same text , and on leaving it replaces the text of the button with the same icons
But For each button I want the text & icon should be differnt.
How can i do this
How can i differentiate all the buttons.
Thanx
Re: Mouse Over Event on QPushButtons
Sounds to me like you're hardcoding the text and icon in the subclass. But these should be member variables of the object.
Maybe you should post your code if this doesn't help you.
Re: Mouse Over Event on QPushButtons
The simplest solution I can think of is this
Code:
PushButton
::PushButton( const QString & text,
const QColor & color,
QWidget * parent,
const char* name
) {
_color = color;
setText(text);
mCustomToolTip = 0;
setMouseTracking(true);
}
Code:
QColor& PushButton::getColor()
{
return _color;
}
Then in CustomToolTip you can have this
Code:
{
p.fillRect( rect(), Qt::transparent );
if( parentWidget() )
{
p.setBrush( ((PushButton*)parentWidget())->getColor() );
p.drawEllipse(rect());
p.drawText(rect(), Qt::AlignCenter, parentWidget()->name());
}
}
Hence there is no need for enterEvent and leaveEvent eventhandlers filters