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.

Qt Code:
  1. myView::myView (QWidget *parent): QWidget(parent)
  2. {
  3. this->setAttribute(Qt::WA_Hover);
  4. }
  5.  
  6. bool myView::event(QEvent *event)
  7. {
  8. if (event->type() == QEvent::HoverMove)
  9. {
  10. QHoverEvent * ke = static_cast<QHoverEvent*>(event);
  11. if (ke->oldPos() == QPoint(-1,-1))
  12. return QWidget::event(event);
  13. QPoint delta = ke->oldPos() - ke->pos();
  14. if ( (std::abs(delta.x()) < 2) && (std::abs(delta.y()) < 2) )
  15. {
  16. //show dialog here
  17. return true;
  18. }
  19.  
  20. }
  21. return QWidget::event(event);
  22. }
To copy to clipboard, switch view to plain text mode