qt02:comboBox的使用

文章详细描述了一个名为Widget02的Qt界面组件,包含了头文件中声明的类及其成员函数,以及源文件中对控件(comboBox和lineEdit)的初始化和事件处理。展示了如何在comboBox中添加选项并监听其变化更新相关LineEdit的内容。
摘要由CSDN通过智能技术生成

头文件

widget02.h

#ifndef WIDGET02_H
#define WIDGET02_H

#include <QWidget>

namespace Ui {
class Widget02;
}

class Widget02 : public QWidget
{
    Q_OBJECT

public:
    explicit Widget02(QWidget *parent = 0);
    ~Widget02();

private slots:
    void on_comboBox_currentIndexChanged(const QString &arg1);

    void on_comboBox_2_currentIndexChanged(const QString &arg1);

    void on_comboBox_3_currentIndexChanged(const QString &arg1);

    void on_lineEdit_2_cursorPositionChanged(int arg1, int arg2);

private:
    Ui::Widget02 *ui;
};

#endif // WIDGET02_H

修改的地方

源文件

widget02.cpp

#include "widget02.h"
#include "ui_widget02.h"

Widget02::Widget02(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget02)
{
    ui->setupUi(this);
    // 单个添加项
            ui->comboBox->addItem("陕西省");
            ui->comboBox->addItem("浙江省");

            // 或者使用字符串列表添加多个项
            QStringList items;
            items << "西安市" << "宝鸡市" << "金华市";
            ui->comboBox_2->addItems(items);

            // 或者使用字符串列表添加多个项
            QStringList items2;
            items2 << "长安区" << "渭滨区" << "不知道区";
            ui->comboBox_3->addItems(items2);
}

Widget02::~Widget02()
{
    delete ui;
}
void Widget02::on_comboBox_currentIndexChanged(const QString &arg1)
{
    QString str=ui->comboBox->currentText();
    ui->lineEdit_2->setText(str);
}

void Widget02::on_comboBox_2_currentIndexChanged(const QString &arg1)
{
    QString str=ui->comboBox_2->currentText();
    ui->lineEdit_3->setText(str);
}


void Widget02::on_comboBox_3_currentIndexChanged(const QString &arg1)
{
    QString str=ui->comboBox_3->currentText();
    ui->lineEdit_4->setText(str);
}

修改的地方

界面文件

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MDY1219

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值