当前位置:网站首页>Qcombox (rewrite) + qcompleter (auto completion, auto loading the drop-down options of qcombox, setting the background color)
Qcombox (rewrite) + qcompleter (auto completion, auto loading the drop-down options of qcombox, setting the background color)
2022-07-05 23:33:00 【Licht powder】
Example :
#ifndef ComplexCombox_H
#define ComplexCombox_H
#include <QObject>
#include <QLineEdit>
#include <QEvent>
#include <QKeyEvent>
#include <QWidget>
#include <QDebug>
#include <QTimer>
#include <QComboBox>
#include <QCompleter>
#include <QStringListModel>
#include <QHeaderView>
#include <QLinearGradient>
#include "lightgroupbutton.h"
#include "data/jsondatamanager.h"
#define COMMOM_ADDR_COLOR "#D3D3D3"
#define USED_ADDR_COLOR "#EEEE00"
class ComplexCombox : public QComboBox
{
Q_OBJECT
public:
explicit ComplexCombox(QWidget *parent = 0);
~ComplexCombox();
protected:
// To load dynamically, you need to rewrite this drop-down function
void showPopup()override;
private:
void initCtr();
void initData();
private:
QComboBox *m_combox;
QCompleter *m_completer;
QList<int> m_qlAddr;
int m_iComboxIndex;
int m_iSelectBtnIndex;
};
#endif // ComplexCombox_H
#include "complexcombox.h"
ComplexCombox::ComplexCombox(QWidget *parent) :
QComboBox(parent)
{
initCtr();
}
ComplexCombox::~ComplexCombox()
{
}
void ComplexCombox::initCtr()
{
m_iComboxIndex=0;
m_iSelectBtnIndex=0;
initData();
setInsertPolicy(QComboBox::InsertAtCurrent);
//setFixedSize(50,20);
setCurrentIndex(0);
setEditable(true);
QRegExp rx("^([A-Da-d]{1}([1-4]{1}[0-9]{2}|[5]{1}[1]{1}[0-2]{1}|[5]{1}[0]{1}[0-9]{1}|[1-9]{1}[0-9]{1}|[1-9]{1}))$");
QRegExpValidator *latitude = new QRegExpValidator(rx,this->lineEdit());
this->lineEdit()->setValidator(latitude);
this->lineEdit()->setCompleter(m_completer);// Filter to be installed in lineEdit Inside , Otherwise it won't work
connect(lineEdit(),SIGNAL(editingFinished()),this,SLOT(slotCboxEditFinished()));
connect(this,SIGNAL(activated(QString)),this,SLOT(slotCboxActived(QString)));
}
void ComplexCombox::initData()
{
QStringList slAddr;
for(int i=0;i<2048;i++)
{
m_qlAddr.append(i);
slAddr << playAddrCovertToSaveAddr(i);
}
m_completer = new QCompleter(slAddr,this);
m_completer->setFilterMode(Qt::MatchStartsWith);
m_completer->setCaseSensitivity(Qt::CaseInsensitive);
}
void ComplexCombox::showPopup()
{
emit sigGetCurtBtnIndex(m_iComboxIndex);// It is not necessary to , What I need
QComboBox::clear();// It is necessary to
QString sCurrentText = this->currentText();// It is necessary to
// Here you can select the data you want to display in the drop-down box
// You can read files and other things , See what you want
for(int i=0;i<m_qlAddr.size();i++)
{
addItem(m_qlAddr.value(i));
if(qlTempUsedAddr.contains(m_qlAddr.value(i)))
{
this->setItemData(i,QColor(USED_ADDR_COLOR),Qt::BackgroundColorRole);
// This can add the background color of the drop-down item , You can also arrange according to your own needs
// Give each of the drop-down boxes item Add colors or pictures with setItemData, Adding colors or pictures depends on the third parameter (this It's overloaded QComboBox)
}
else
{
this->setItemData(i,QColor(COMMOM_ADDR_COLOR),Qt::BackgroundColorRole);
}
}
setCurrentText(sCurrentText);// It is necessary to
QComboBox::showPopup();// It is necessary to
}
QComboBox Custom style ( Reload drop-down box ) Comprehensive usage
边栏推荐
- Practice of concurrent search
- How to insert data into MySQL database- How can I insert data into a MySQL database?
- YML configuration, binding and injection, verification, unit of bean
- Go language introduction detailed tutorial (I): go language in the era
- Calculating the number of daffodils in C language
- yate. conf
- The maximum happiness of the party
- C Primer Plus Chapter 9 question 10 binary conversion
- Basic knowledge of database (interview)
- 【LeetCode】5. Valid Palindrome·有效回文
猜你喜欢
How to quickly understand complex businesses and systematically think about problems?
Realize reverse proxy client IP transparent transmission
There are 14 God note taking methods. Just choose one move to improve your learning and work efficiency by 100 times!
14种神笔记方法,只需选择1招,让你的学习和工作效率提高100倍!
Practice of concurrent search
TVS管 与 稳压二极管参数对比
Huawei simulator ENSP - hcip - MPLS experiment
Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
Data type, variable declaration, global variable and i/o mapping of PLC programming basis (CoDeSys)
Using LNMP to build WordPress sites
随机推荐
动态规划 之 打家劫舍
代码农民提高生产力
Golang code checking tool
The maximum happiness of the party
February 13, 2022 -5- maximum depth of binary tree
【经典控制理论】自控实验总结
帶外和帶內的區別
Use of grpc interceptor
Leetcode buys and sells stocks
3D point cloud slam
poj 2762 Going from u to v or from v to u? (infer whether it is a weak link diagram)
开关电源Buck电路CCM及DCM工作模式
芯源&立创EDA训练营——无刷电机驱动
TVS管和ESD管的技术指标和选型指南-嘉立创推荐
Using LNMP to build WordPress sites
2: Chapter 1: understanding JVM specification 1: introduction to JVM;
Scala concurrent programming (II) akka
CorelDRAW plug-in -- GMS plug-in development -- new project -- macro recording -- VBA editing -- debugging skills -- CDR plug-in (2)
UVA11294-Wedding(2-SAT)
证明 poj 1014 模优化修剪,部分递归 有错误