zoukankan      html  css  js  c++  java
  • 鼠标响应事件

     1 #ifndef MAINWINDOW_H
     2 #define MAINWINDOW_H
     3 
     4 #include <QMainWindow>
     5 #include <QMouseEvent>
     6 #include <QWheelEvent>
     7 
     8 class MainWindow : public QMainWindow
     9 {
    10     Q_OBJECT
    11     
    12 public:
    13     MainWindow(QWidget *parent = 0);
    14     ~MainWindow();
    15 
    16 protected:
    17     void mousePressEvent(QMouseEvent *event);//点击
    18     //void mouseMoveEvent(QMouseEvent *event);//移动
    19     //void mouseReleaseEvent(QMouseEvent *event);//释放
    20     //void mouseDoubleClickEvent(QMouseEvent *event);//双击
    21     //void wheelEvent(QWheelEvent *event);//滚动
    22 
    23 private:
    24     QPoint offset;//存储鼠标位置与窗口位置的差值
    25     QCursor cursor;//创建光标,保存光标的默认形状
    26 };
    27 
    28 #endif // MAINWINDOW_H
    29 
    30 //鼠标触发事件
     1 #include "mainwindow.h"
     2 #include <QMouseEvent>
     3 #include <QDebug>
     4 
     5 MainWindow::MainWindow(QWidget *parent)
     6     : QMainWindow(parent)
     7 {
     8     //mousePressEvent(QMouseEvent *event);
     9     //mouseDoubleClickEvent();
    10     //mouseMoveEvent();
    11     //mouseReleaseEvent();
    12     //wheelEvent();
    13 }
    14 
    15 MainWindow::~MainWindow()
    16 {
    17     
    18 }
    19 //左右键点击事件,打印消息
    20 void MainWindow::mousePressEvent(QMouseEvent *event)
    21 {
    22     if(event->buttons()==Qt::LeftButton)
    23     {
    24         //cursor = new QCursor;
    25         qDebug()<<"LeftButton clicked!";
    26     }
    27     else if(event->button()==Qt::RightButton)
    28         qDebug()<<"RightButton clicked!";
    29 }
    30 /*void MainWindow::mouseMoveEvent(QMouseEvent *event)
    31 {
    32 
    33 }
    34 void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
    35 {
    36     if(event->button()==)
    37 }*/
  • 相关阅读:
    cocos2d-x编译到android平台后,增加返回键和菜单键支持
    Android 网络权限配置
    Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
    Andorid第三方库
    JS计算字符串长度(中文算2个)
    JSP table中除了第一行(标题)其他全清空
    [转]整理jquery开发技巧
    [转]整理jquery使用好习惯
    把对象转换成map
    Java ZIP打包
  • 原文地址:https://www.cnblogs.com/Blue-Moniter4/p/9660432.html
Copyright © 2011-2022 走看看