zoukankan      html  css  js  c++  java
  • QT UI拖拽方法

    添加方法

    实现点击事件 移动位置

    其他不变的

    通过 https://www.cnblogs.com/luoxiang/p/6497670.html 来实现的

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    
    #include <QMainWindow>
    #include <QMouseEvent>
    
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    
    private:
        Ui::MainWindow *ui;
        void on_pushButton_clicked();
        void mousePressEvent(QMouseEvent *e);
        void mouseMoveEvent(QMouseEvent *e);
        QPoint M_point;
    };
    #endif // MAINWINDOW_H


    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QMouseEvent>
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    void MainWindow::mousePressEvent(QMouseEvent *e)
    {
        if (e->button() == Qt::LeftButton) {
            M_point = e->globalPos() - pos();
            e->accept();
        }
    }
    
    
    void MainWindow::mouseMoveEvent(QMouseEvent *e)
    {
        if (e->buttons() & Qt::LeftButton) {
            move(e->globalPos() - M_point);
            e->accept();
        }
    }
    
    


  • 相关阅读:
    你可见过一种基于状压的二进制筛法?
    dp
    tricks
    csp2020 游记
    洛谷P2982 [USACO10FEB]慢下来Slowing down
    NOIP 2018 大翻车记
    2019 ICPC 南京网络赛
    POJ2778 AC自动机 + 快速矩阵幂
    2019 CCPC网络赛
    2018ICPC 北京
  • 原文地址:https://www.cnblogs.com/suiyi78/p/13799707.html
Copyright © 2011-2022 走看看