Rewrite
mousedoubleclickevent (qmouseevent event) *1. Example: Output "SSS" when double-clicking the window
/*widget.h*/ #ifndef widget_h #define widget_h #include <qwidget> #include <qdebug> class Widget: public qwidget{q_objectpublic : widget (qwidget * Parent=0 ); ~widget () {}protected ://Declaration void mousedoubleclickevent (qmouseevent*);}; #endif
/*widget.cpp*/ #include "widget.h" #include < qmouseevent> Widget ::widget (Qwidget* parent ): Qwidget ( parent ) {}//override void widget:: Mousedoubleclickevent (Qmouseevent* event) {Qdebug ( );
/*main.cpp*/#include"widget.h"#include<QApplication>int main(int argc,char* argv[]){ QApplication app(argc,argv); Widget w; w.show(); return app.exec();}
After I put the listwidget in the widget, I rewrote the mousedoubleclickeventin the widget class, but I don't know why I can't trigger it. Then rewrite the mousedoubleclickeventin the Listwidget class so that the mouse double-click event can be triggered.
2, left-click, right-click
?? The above default is the mouse around the key, you can also determine whether the left-click or right-click Trigger:
void Widget::mouseDoubleClickEvent(QMouseEvent* event){ if(event->button()==Qt::LeftButton) qDebug("Left"); if(event->button()==Qt::RightButton) qDebug("Right");}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
QT Mouse Double click events mousedoubleclickevent (qmouseevent* event)