0

QT添加下拉框_五个板栗的技术博客_51CTO博客

 1 year ago
source link: https://blog.51cto.com/u_15515702/5913059
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

QT添加下拉框

精选 原创

五个板栗 2022-12-05 16:37:36 博主文章分类:Qt ©著作权

文章标签 下拉框 ui界面 QT 文章分类 C/C++ 编程语言 yyds干货盘点 阅读数162

1.在ui界面上有一个名为comboBox_content的下拉框,向其添加四个下拉内容,QModbusDataUnit是QModbusTcpClient的成员

//四种通信内容:线圈(Coil)、离散量输入(Discrete Inputs)、输入寄存器 (Input Registers)
//保持寄存器(Holding Registers)、
ui->comboBox_content->addItem(tr("Coils"), QModbusDataUnit::Coils);
ui->comboBox_content->addItem(tr("Discrete Inputs"), QModbusDataUnit::DiscreteInputs);
ui->comboBox_content->addItem(tr("Input Registers"), QModbusDataUnit::InputRegisters);
ui->comboBox_content->addItem(tr("Holding Registers"), QModbusDataUnit::HoldingRegisters);
QT添加下拉框_QT

2,在ui界面上有一个名为comboB的下拉框,向其添加数字

不写代码,直接添加方式:

QT添加下拉框_下拉框_02

QT添加下拉框_下拉框_03

设置默认指针位置

QT添加下拉框_下拉框_04
代码方式:
auto model = new QStandardItemModel(10, 1, this);
for (int i = 0; i < 10; ++i)
model->setItem(i, new QStandardItem(QStringLiteral("%1").arg(i + 1)));
ui->writeSize->setModel(model);
ui->writeSize->setCurrentText("10");
QT添加下拉框_QT_05
QT添加下拉框_QT_06
  • 收藏
  • 评论
  • 分享
  • 举报

上一篇:QT实现Modbus


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK