Ok, no time to review.
What you can do is take the below code, cut and paste into a new project and then try.
NOTE: you have to place the mouse cursor on the button stable for a while, then move slightly to see the eclipse.
//.h
{
Q_OBJECT
public:
~PushButton(){}
protected:
private:
CustomToolTip *mCustomToolTip;
};
class PushButton : public QPushButton
{
Q_OBJECT
public:
PushButton( const QString & text, QWidget * parent = 0 );
~PushButton(){}
protected:
bool event ( QEvent * );
void mouseMoveEvent( QMouseEvent* );
private:
CustomToolTip *mCustomToolTip;
QPoint _mousePoint;
};
To copy to clipboard, switch view to plain text mode
//.cpp
{
setText(text);
mCustomToolTip = 0;
setMouseTracking(true);
}
bool PushButton
::event( QEvent * e
) {
if(he
&& he
->type
() == QEvent::ToolTip) {
if(!mCustomToolTip)
mCustomToolTip = new CustomToolTip( this);
mCustomToolTip->show();
e->accept();
return true;
}
else
{
if(mCustomToolTip)
mCustomToolTip->hide();
}
}
{
_mousePoint = e->pos() ;
}
PushButton::PushButton( const QString & text, QWidget * parent )
: QPushButton(parent)
{
setText(text);
mCustomToolTip = 0;
setMouseTracking(true);
}
bool PushButton::event( QEvent * e )
{
QHelpEvent *he = static_cast<QHelpEvent*>(e);
if(he && he->type() == QEvent::ToolTip)
{
if(!mCustomToolTip)
mCustomToolTip = new CustomToolTip( this);
mCustomToolTip->show();
e->accept();
return true;
}
else
{
if(mCustomToolTip)
mCustomToolTip->hide();
}
return QWidget::event(e);
}
void PushButton::mouseMoveEvent( QMouseEvent* e)
{
_mousePoint = e->pos() ;
}
To copy to clipboard, switch view to plain text mode
//.h
class CustomToolTip
: public QWidget{
Q_OBJECT
public:
CustomToolTip
( QWidget * parent
= 0 );
~CustomToolTip(){}
protected:
private:
};
class CustomToolTip : public QWidget
{
Q_OBJECT
public:
CustomToolTip( QWidget * parent = 0 );
~CustomToolTip(){}
protected:
void paintEvent ( QPaintEvent * );
private:
};
To copy to clipboard, switch view to plain text mode
//.cpp
CustomToolTip
::CustomToolTip( QWidget * parent
){
setWindowFlags(Qt::ToolTip);
resize( 50, 50 );
}
{
p.fillRect( rect(), Qt::transparent );
p.setBrush(Qt::red);
p.drawEllipse(rect());
}
CustomToolTip::CustomToolTip( QWidget * parent )
:QWidget(parent)
{
setWindowFlags(Qt::ToolTip);
resize( 50, 50 );
}
void CustomToolTip::paintEvent ( QPaintEvent * )
{
QPainter p(this);
p.fillRect( rect(), Qt::transparent );
p.setBrush(Qt::red);
p.drawEllipse(rect());
}
To copy to clipboard, switch view to plain text mode
//main.cpp
int main(int argc, char *argv[])
{
PushButton* pBtn = new PushButton("OK", &w);
w.resize(400, 500);
pBtn->setGeometry( w.width()/2, w.height()/2, 80, 30 );
w.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
PushButton* pBtn = new PushButton("OK", &w);
w.resize(400, 500);
pBtn->setGeometry( w.width()/2, w.height()/2, 80, 30 );
w.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks