About the custom status bar
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.
Re: About the custom status bar
This will not work. QApplication::widgetAt() expects a global screen position and event->pos() gives position of the mouse cursor, relative to the widget that received the event
Quote:
With this method, prompts("over pushbutton") in the status bar, but the pushbutton isn't display in the window.
You code should look like this
Code:
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(""));
}
else
{
ui->statusbar->setToolTip(tr(""));
}
return QWidget::eventFilter(obj,event
);
Re: About the custom status bar
I want to know how to create a custom status bar?
I can't find out a way to solve this pragram.