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 }*/
  • 相关阅读:
    spring基于xml导入配置文件
    spring中bean的继承和依赖关系
    spring整合junit
    spring新注解说明
    Web微信开发工具无法输入中文?官方bug
    vue踩坑 导出new Vue.Store首字母要大写
    关于vue ui组件
    vue组件的生命周期
    Vue的指令以及组件化开发
    webpack的npm扩展使用
  • 原文地址:https://www.cnblogs.com/Blue-Moniter4/p/9660432.html
Copyright © 2011-2022 走看看