PDA

View Full Version : About the custom status bar



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.

Santosh Reddy
28th March 2013, 15:53
QWidget *widget = QApplication::widgetAt(event->pos());
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



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


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);

Hughen
31st March 2013, 03:57
I want to know how to create a custom status bar?
I can't find out a way to solve this pragram.