Hughen
28th March 2013, 15:13
Now I need a custom status bar, and I try to overload mouseMoveEvent(QMouseEvent *event), code is as follows:
qDebug()<<QCursor:: pos().x()<<QCursor:: pos().y();
QWidget *widget = QApplication::widgetAt(event->pos());
if(widget == ui->pushButton)
ui->statusbar->setToolTip(tr("button"));
(I set mouse with tracking before this code, by setMouseTracking(true))
When I move mouse over the pushbutton, and no display on the status bar, I'm very sad, what's happened??
And I try to another method to solve the custom status bar, with eventFilter(QObject *obj, QEvent *event), code is as follows:
if(obj == ui->pushButton)
{
if(event->type() == QEvent::Enter)
{
ui->statusbar->setToolTip(tr("over pushbutton"));
}
else if(event->type() == QEvent::Leave)
ui->statusbar->setToolTip(tr(""));
return true;
}
else
{
ui->statusbar->setToolTip(tr(""));
return QWidget::eventFilter(obj,event);
}
With this method, prompts("over pushbutton") in the status bar, but the pushbutton isn't display in the window.
qDebug()<<QCursor:: pos().x()<<QCursor:: pos().y();
QWidget *widget = QApplication::widgetAt(event->pos());
if(widget == ui->pushButton)
ui->statusbar->setToolTip(tr("button"));
(I set mouse with tracking before this code, by setMouseTracking(true))
When I move mouse over the pushbutton, and no display on the status bar, I'm very sad, what's happened??
And I try to another method to solve the custom status bar, with eventFilter(QObject *obj, QEvent *event), code is as follows:
if(obj == ui->pushButton)
{
if(event->type() == QEvent::Enter)
{
ui->statusbar->setToolTip(tr("over pushbutton"));
}
else if(event->type() == QEvent::Leave)
ui->statusbar->setToolTip(tr(""));
return true;
}
else
{
ui->statusbar->setToolTip(tr(""));
return QWidget::eventFilter(obj,event);
}
With this method, prompts("over pushbutton") in the status bar, but the pushbutton isn't display in the window.