当前位置:网站首页>[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_H
mycombobox.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 ;
边栏推荐
- COMP1721 Creating Classes
- appliedzkp的zkevm(12)State Proof
- [matlab] general function of communication signal modulation - generation of narrow-band Gaussian white noise
- Annex 2-2 confidentiality commitment docx
- Annex II: confidentiality agreement for offensive and defensive drills docx
- How to build your own knowledge engine? Community open application
- Sécurité du réseau dans les écoles professionnelles secondaires - preuve de mémoire
- [matlab] communication signal modulation general function interpolation function
- Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
- Remote desktop client RDP
猜你喜欢
Etcd database source code analysis - initialization overview
如何构建属于自己的知识引擎?社群开放申请
Automated testing selenium foundation -- webdriverapi
TCP state transition diagram
National vocational college skills competition (secondary vocational group) network security competition questions - Analysis
2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
数据标注是一块肥肉,盯上这块肉的不止中国丨曼孚科技
企业级日志分析系统ELK(如果事与愿违那一定另有安排)
Just do it with your hands 7 - * project construction details 2 - hook configuration
LabVIEW错误对话框的出现
随机推荐
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
Thread pool: use thread pool to optimize query speed
Exercise bubble sort
2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
Capturing and sorting out external Fiddler -- Conversation bar and filter
LM small programmable controller software (based on CoDeSys) note XXI: error 3703
由于使用flash存放参数时,擦除掉了flash的代码区导致进入硬件错误中断
Trie数-字典树
laravel 中获取刚刚插入的记录的id
c语言经典指针和数组笔试题解析
VB.net GIF(制作、拆解——优化代码,类库——5)
Get the ID of the record just inserted from laravel
ping端口神器psping
C语言简易学生管理系统(含源码)
模拟小根堆
【兴趣阅读】Adversarial Filtering Modeling on Long-term User Behavior Sequences for Click-Through Rate Pre
Character types of C language
[matlab] communication signal modulation general function interpolation function
简单g++和gdb调试
[matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system