当前位置:网站首页>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
边栏推荐
- Différence entre hors bande et en bande
- Go language implementation principle -- lock implementation principle
- February 13, 2022-4-symmetric binary tree
- CIS基准测试工具kube-bench使用
- [classical control theory] summary of automatic control experiment
- UVA11294-Wedding(2-SAT)
- How to quickly understand complex businesses and systematically think about problems?
- asp.net弹出层实例
- Hcip course notes-16 VLAN, three-tier architecture, MPLS virtual private line configuration
- (4)UART應用設計及仿真驗證2 —— TX模塊設計(無狀態機)
猜你喜欢

The PNG image is normal when LabVIEW is opened, and the full black image is obtained when Photoshop is opened

STM32__06—单通道ADC

Go语言实现原理——Map实现原理

YML configuration, binding and injection, verification, unit of bean

From the perspective of quantitative genetics, why do you get the bride price when you get married

Hcip course notes-16 VLAN, three-tier architecture, MPLS virtual private line configuration

Huawei simulator ENSP - hcip - MPLS experiment

开关电源Buck电路CCM及DCM工作模式

February 13, 2022-4-symmetric binary tree

Scala concurrent programming (II) akka
随机推荐
C# Linq Demo
UART Application Design and Simulation Verification 2 - TX Module Design (Stateless machine)
The PostgreSQL column reference 'ID' is ambiguous - PostgreSQL column reference'id'is ambiguous
From the perspective of quantitative genetics, why do you get the bride price when you get married
Three. Js-01 getting started
What is the process of building a website
grafana工具界面显示报错influxDB Error
How to design API return code (error code)?
UVA11294-Wedding(2-SAT)
Debian 10 installation configuration
Common static methods of math class
White hat talks about web security after reading 2
Difference between out of band and in band
Leetcode sword finger offer brush questions - day 21
Leecode learning notes
Switching power supply buck circuit CCM and DCM working mode
Rasa 3.x 学习系列-Rasa X 社区版(免费版) 更改
yate. conf
并查集实践
Cwaitabletimer timer, used to create timer object access