I have QWidget-derived class where I am painting custom view. I’d like the user to be able to move the mouse pointer to a certain position within the view boundaries. When the mouse pointer reaches this point and user stops I need to display the dialog.
I don’t think I can use QAction because my view is not a toolbar or a menu. So, I turned to events and this is my current implementation. The problem is that these events are generated all the time. I can’t figure out a way to find the time to actually show my dialog – events are too “small†to detect specific time when the mouse is actually stopped moving.
Your advise will be greatly appreciated.
{
this->setAttribute(Qt::WA_Hover);
}
bool myView
::event(QEvent *event
) {
if (event
->type
() == QEvent::HoverMove) {
if (ke
->oldPos
() == QPoint(-1,
-1)) QPoint delta
= ke
->oldPos
() - ke
->pos
();
if ( (std::abs(delta.x()) < 2) && (std::abs(delta.y()) < 2) )
{
//show dialog here
return true;
}
}
}
myView::myView (QWidget *parent): QWidget(parent)
{
this->setAttribute(Qt::WA_Hover);
}
bool myView::event(QEvent *event)
{
if (event->type() == QEvent::HoverMove)
{
QHoverEvent * ke = static_cast<QHoverEvent*>(event);
if (ke->oldPos() == QPoint(-1,-1))
return QWidget::event(event);
QPoint delta = ke->oldPos() - ke->pos();
if ( (std::abs(delta.x()) < 2) && (std::abs(delta.y()) < 2) )
{
//show dialog here
return true;
}
}
return QWidget::event(event);
}
To copy to clipboard, switch view to plain text mode
Bookmarks