当前位置:网站首页>[QT] create mycombobox click event
[QT] create mycombobox click event
2022-07-04 05:19:00 【Miguel's voice】
stay QT Medium ui Interface add QComboBox Control , The requirement is to implement the click event of the control , Checked the data , It is found that the control class itself has no click signal to use . Make ComboBox Click events can be divided into three steps :
1、 rewrite ComboBox class ;
2、 stay widget Add the corresponding start signal and slot event ;
3、 stay ui Window will ComboBox Control is promoted to the overridden class ;
mycombobox.h
#ifndef MYCOMBOBOX_H
#define MYCOMBOBOX_H
#include <QComboBox>
#include <QMouseEvent>
class MyComboBox : public QComboBox
{
Q_OBJECT// Only join Q_OBJECT, To use the signal signal Slot slot The mechanism of
public:
explicit MyComboBox(QWidget *parent = 0);
~MyComboBox();
protected:
virtual void mousePressEvent(QMouseEvent *e);// Add mouse click events
signals:
void clicked();// Custom click signal , stay mousePressEvent Trigger when an event occurs
};
#endif // MYCOMBOBOX_Hmycombobox.c
#include "mycombobox.h"
MyComboBox::MyComboBox(QWidget *parent) : QComboBox(parent)
{
}
MyComboBox::~MyComboBox()
{
}
// rewrite mousePressEvent event , Check whether the event type is left click
void MyComboBox::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
{
emit clicked(); // Trigger clicked The signal
}
QComboBox::mousePressEvent(e); // Pass the event to the parent class for processing , This sentence is very important , without , The parent class cannot handle the original click event
}
mainwindow.h
public slots:
void ComboBoxClicked();// Add slot function mainwindow.c
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Add links , When you click send to ComboBoxClicked()
connect(ui->cbb_pztWorkModel, SIGNAL(clicked()), this, SLOT(ComboBoxClicked()));
}
void MainWindow::ComboBoxClicked() {
ui->statusbar->showMessage(" Please enter the correct even number Hex character (Hex Characters contain only 0~9、A~F、 Space )", 2000);
}
About lineEdit The promotion steps of the control are , Click to enter the window ui Design interface —— Choose ComboBox Control —— Right click —— Upgrade to —— Add the newly rewritten class to the promoted class name MyComboBox, Then select —— promote ;

边栏推荐
- Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
- Encryption and decryption
- June 2022 summary
- Automated testing selenium foundation -- webdriverapi
- c语言经典指针和数组笔试题解析
- How to build your own knowledge engine? Community open application
- Useful plug-ins for vscode
- Zkevm (12) state proof of appliedzkp
- 空洞卷积、可变形卷积、可变形ROI Pooling
- 由于使用flash存放参数时,擦除掉了flash的代码区导致进入硬件错误中断
猜你喜欢

2022G2电站锅炉司炉特种作业证考试题库及答案

Analysis of classical pointer and array written test questions in C language

抓包整理外篇fiddler———— 会话栏与过滤器

中职组网络安全—内存取证
![[paper summary] zero shot semantic segmentation](/img/78/ee64118d86a7e43ec4d1cb97191fbe.jpg)
[paper summary] zero shot semantic segmentation

Daily question brushing record (12)

Appearance of LabVIEW error dialog box

How to build your own knowledge engine? Community open application

Just do it with your hands 7 - * project construction details 2 - hook configuration

【兴趣阅读】Adversarial Filtering Modeling on Long-term User Behavior Sequences for Click-Through Rate Pre
随机推荐
基于单片机的太阳能杀虫系统
We believe that the development of consumer Internet will still be limited to the Internet industry itself
Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
2022危险化学品经营单位安全管理人员上岗证题库及答案
练习-冒泡排序
补某视频网站的js,进行视频解密
appliedzkp的zkevm(12)State Proof
C语言简易学生管理系统(含源码)
Remote desktop client RDP
中科磐云—2022广西逆向解析思路
Etcd database source code analysis - initialization overview
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
2022 question bank and answers for safety management personnel of hazardous chemical business units
[matlab] matlab simulation of modulation system - power spectrum and coherent demodulation of AM modulated signal
Notepad++ -- display related configurations
Exercise bubble sort
appliedzkp zkevm(11)中的EVM Proof
Trie数-字典树
Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
Just do it with your hands 7 - * project construction details 2 - hook configuration