QComboBox

下拉列表

editable 可编辑的下拉列表

currentText 当前选中的文本内容
currentIndex 当前文本的下标,0表示第一个,以此类推,-1表示没有任何值

maxVisibleItems 最多显示下拉项的数目
maxCount 下拉列表中的下拉项最多的个数,超过会把后面的覆盖掉

insertPolicy 向下拉列表中,插入下拉项的位置

QComboBox::NoInsert
QComboBox::InsertAtTop
QComboBox::InsertAtCurrent
QComboBox::InsertAtBottom
QComboBox::InsertAfterCurrent
QComboBox::InsertBeforeCurrent
QComboBox::InsertAlphabetically 根据字母排序插入

minimumContentLength 下拉列表中最小的字符个数 默认为0

duplicatesEnabled 下拉列表中存在重复项,默认false

frame 边框是否存在,默认存在

//插入分割符
void QComboBox::insertSeparator(int index)

信号

Activated 当用户选中一个下拉选项时发射该信号
currentIndexChanged 当下拉选项的索引发生改变时发射该信号
highlighted 当选中一个已经选中的下拉选项时,发射该信号 鼠标在下拉列表中滑动,触发该信号

//注意下面的信号是重载的,使用时要用强制类型转换
void activated(int index)
void activated(const QString &text)
void currentIndexChanged(int index)
void currentIndexChanged(const QString &text)

    this->ui->comboBox_2->insertSeparator(2);
    this->ui->comboBox_2->insertSeparator(4);

    this->ui->comboBox_2->addItem("07");
    this->ui->comboBox_2->addItem("08");

    this->ui->comboBox_2->setInsertPolicy(QComboBox::InsertAtTop);
    this->ui->comboBox_2->addItem("10");

    typedef void (QComboBox::*QComboIntSignal)(int);
    connect(this->ui->comboBox_3, static_cast<QComboIntSignal>(&QComboBox::activated),
            [](int index)
            {
                qDebug() << "下拉列表改变为" << index << "下标";
            }
    );

//    connect(this->ui->comboBox_2
//            , static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
//            [](const QString &text)
//            {
//                qDebug() << text;
//            }
//            );

猜你喜欢

转载自blog.csdn.net/weixin_43340991/article/details/89462220