How to tell the mouse button using QApplication::mouseButtons() in a “click” slot?

后端 未结 3 1863
忘掉有多难
忘掉有多难 2021-01-26 01:21

I have a QMainWindow, and want to handle the \"clicked\" signal from a smaller widget (such as tableview) inside it.

Originally I connect the signal to a slot of this QM

3条回答
  •  生来不讨喜
    2021-01-26 01:54

    for "connect" use this:

    connect(moduleTree,SIGNAL(itemClicked(QTreeWidgetItem *,int )),this
            ,SLOT(SlotItemClicked(QTreeWidgetItem *, int)));
    

    define a global flag:

    public:
    Qt::MouseButton mouseClickedBtnFlag;
    

    and then reimplement "mouseReleaseEvent":

    CGuiMainwindow::mouseReleaseEvent ( QMouseEvent * event )
    {
    mouseClickedBtnFlag = event->button();
    }
    

    and then:

    void CGuiMainwindow::SlotItemClicked(QTreeWidgetItem *item, int column)
    {    
     if (mouseClickedBtnFlag == Qt::LeftButton)              
     { return; }              
    
     if (mouseClickedBtnFlag == Qt::RightButton)              
     {              
        ......              
     }
    }
    

提交回复
热议问题