QT Mouse Double click events mousedoubleclickevent (qmouseevent* event)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.