Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A bug when show menu and then moving fast the widget?
Forum Updated to NodeBB v4.3 + New Features

A bug when show menu and then moving fast the widget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 509 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AA130
    wrote on last edited by AA130
    #1

    the code is very easy:
    1.right click show the menu
    2.left click move the widget

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {class MainWindow;}
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    public:
        explicit MainWindow(QWidget *parent = 0);
        void contextMenuEvent(QContextMenuEvent *);
        ~MainWindow();
    protected:
        virtual void mousePressEvent(QMouseEvent *event);
        virtual void mouseMoveEvent(QMouseEvent *event);
        virtual void mouseReleaseEvent(QMouseEvent *event);
    private:
        Ui::MainWindow *ui;
        bool		mMoveing;
        QPoint	    mMovePosition;
    };
    #endif // MAINWINDOW_H
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QtGui/QMouseEvent>
    #include <QMenu>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        resize(100,100);
    }
    
    void MainWindow::contextMenuEvent(QContextMenuEvent *e)
    {
        QMenu *m =new  QMenu(this);
        m->addAction("item1");
    
        m->exec(e->globalPos());
    }
    
    MainWindow::~MainWindow(){delete ui;}
    
    void MainWindow::mousePressEvent(QMouseEvent *event)
    {
        mMoveing = true;
        mMovePosition = event->globalPos() - pos();
        return QWidget::mousePressEvent(event);
    }
    
    
    void MainWindow::mouseMoveEvent(QMouseEvent *event)
    {
        if (mMoveing && (event->buttons() && Qt::LeftButton))
        {
            move(event->globalPos()-mMovePosition);
            mMovePosition = event->globalPos() - pos();
        }
        return QWidget::mouseMoveEvent(event);
    }
    void MainWindow::mouseReleaseEvent(QMouseEvent *event)
    {
        mMoveing = false;
    }
    
    

    but, when I show the menu and then moving the widget fast, the widget would not follow the mouse
    like this:
    0_1539659180029_111.gif

    however, if no right click, its OK
    0_1539659336183_222.gif

    what problem here is? the problem same show in pyqt too

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What version of Qt ?
      On what platform ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • A Offline
        A Offline
        AA130
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          What version of Qt ?
          On what platform ?

          A Offline
          A Offline
          AA130
          wrote on last edited by
          #4

          @SGaist Win7 64 and QT 5.10.1/pyqt 5.11.2

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved