当前位置:网站首页>QT control adds double click event
QT control adds double click event
2022-06-22 08:04:00 【Licht powder】
One 、 overloaded function mouseDoubleClickEvent
class SpinBoxAndCombox: public QWidget
{
Q_OBJECT
protected:
// Then re implement the mouse double click event
void mouseDoubleClickEvent(QMouseEvent* e);
public:
SpinBoxAndCombox(QWidget* parent = nullptr) : SpinBoxAndCombox(parent){ };
};
void SpinBoxAndCombox::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton)
{
qDebug() << "12345";
}
}Two 、 Event filter
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
protected:
virtual bool eventFilter(QObject * obj,QEvent *event) override;
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->widget->installEventFilter(this);//widget Control to install the event filter
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == ui->widget) // The object you want to filter
if (event->type() == QEvent::MouseButtonDblClick)
{ // The event type of the object you want to filter
// What you want to achieve , My implementation here is to create a new tab and a new text edit bar
return true; // Note that you must return here true, Indicates that you want to filter the original implementation of the event
}
return false; // return false Indicates no filtering , Also by default
}边栏推荐
- Technology blog collection
- Common array operations in JS
- Canvastotempfilepath of wechat
- MySQL intercepts the string cs0000_ 1 medium_ Following characters
- 【Oracle 數據庫】奶媽式教程 day13 日期函數
- Model electricity experiment -- Experiment 1 transistor common emitter single transistor amplifier
- 【Oracle 数据库】奶妈式教程 day12 字符函数
- MySQL delete from and subquery as conditions
- Fmdb usage details mark
- MySQL master-slave replication
猜你喜欢

navicat如何查询已连接的数据库密码信息
关于菲涅尔现象

QT combox的使用示例

Kubernetes practice

Failed to access the ES installed on Tencent ECs, but the solution to accessing the ES successfully on the server

0基础自学stm32(野火)——什么是寄存器?

模电实验——实验一 晶体管共射极单管放大器

Website sharing of program ape -- continuous update

MySQL view

(7) Bidirectional linked list
随机推荐
The significance of code coverage testing to programming white and its application
Download addresses of Xcode versions
Chmod Chmod command
MySQL queries data within one hour
矩阵运算
Kotlin a simple Android program
MySQL transactions
The applet uses the step bar vant steps in vant
How to handle root password forgetting in MySQL
Note pad replaces all contents after a character in all lines
Restrict input type (multiple methods)
Docker install redis
Asynchronous sending and receiving of message passing based concurrent programming (MPI)
[Oracle database] wet nurse tutorial day15 DDL, DML, index, view, sequence and deadlock are enough
Template code overview
AutoCAD 2020.3中文版 (旧版本)
QT combox的使用示例
基于消息传递的并发编程(MPI)之异步收发
Canvastotempfilepath of wechat
lr 2022超详细安装教程「最新」