首页 > 其他分享 >QtGui开发随笔

QtGui开发随笔

时间:2023-01-11 15:22:05浏览次数:37  
标签:QtGui cb QComboBox 开发 QString QLineEdit new 随笔

Gui开发随笔

QLabel、QCombobox这类控件在addWidget时如果设置了Qt::AlignRight 就不会随窗口的变化而变化

QComboBox

显示数据量太大时加载比较耗时

QComboBox *cb = new QComboBox();

按字母排序:

cb->model()->sort(0);

自动匹配下拉:

QCompleter *cp = new QComPleter(cb->model(), this); // 这句话要在comboxBox 添加完数据之后设置
cb->setCompleter(cp);

设置不能插入新的数据:

cb->setInsertPolicy(QComboBox::NoInsert);

QTableView

QTableView显示大量数据卡时可以分页显示

QString

QString 判断是否以什么开头

QString str = "adfg";
str.startsWith("ad");

QLineEdit

可以通过setValidator对输入进行限制

QLineEdit* le = new QLineEdit("1", this); // 构造一个初始值为 1 的QlineEdit
QRegExp reg("^[1-9][0-9]"); //只能输入 1-99 的数字
le->setValidator(new QRegExpValidator(reg, this));

QtCreator 添加qt版本不可用

标签:QtGui,cb,QComboBox,开发,QString,QLineEdit,new,随笔
From: https://www.cnblogs.com/AngleLin/p/16982627.html

相关文章