Inputwidget

QComboBox

是一个窗口部件,有按钮和弹出列表组成

addItem() 增加一个下拉选项
setMaxVisibleItems() 设置下拉项最多显示几个,超过个数使用滚动条
setInsertPolicy() 设置插入方式
currentIndex() 当前项索引
currentText() 当前项文本
findText(“abc”) 获得abc内容的索引
currentIndexChanged(int) 当前索引改变信号

在这里插入图片描述
ui界面绿色框框是这个控件的一些控制

#include "widget.h"
#include "ui_widget.h"
#include "qDebug"
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    
    
    ui->setupUi(this);
    initComboBox();
    initSearchLineEdit();
}

Widget::~Widget()
{
    
    
    delete ui;
}

void Widget::initSearchLineEdit()
{
    
    

    ui->searchLineEdit->setPlaceholderText(QObject::tr("搜索程序和文件"));

    // 添加action
    QAction *searchLineEditLeadingAction = new QAction(this);
    searchLineEditLeadingAction->setIcon(QIcon(":/image/leading.png"));

    ui->searchLineEdit->addAction(searchLineEditLeadingAction, QLineEdit::LeadingPosition);
    QAction *searchLineEditTrailingAction = ui->searchLineEdit->addAction(QIcon("://image/trailing.png"), QLineEdit::TrailingPosition);

    // 连接信号和槽
    connect(searchLineEditTrailingAction, SIGNAL(triggered(bool)), this, SLOT(slotSearchLineEdit(bool)));
}

void Widget::initComboBox()
{
    
    
    ui->comboBox->addItem("555");//增加一个下拉选项
    ui->comboBox->setMaxVisibleItems(4);//设置最大显示数量
    ui->comboBox->setInsertPolicy(QComboBox::InsertAtTop);//
   // ui->comboBox->setInsertPolicy(QComboBox::InsertAtBottom);
    connect(ui->comboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(slotComboBoxcurrentIndexChanged(int)));
    connect(ui->fontComboBox,SIGNAL(currentFontChanged(QFont)),this,SLOT(slotFontComboBoxcurrentIndexChanged(QFont)));
}

void Widget::slotComboBoxcurrentIndexChanged(int index)
{
    
    
    qDebug()<<index;
    qDebug()<<ui->comboBox->currentIndex();
    qDebug()<<ui->comboBox->currentText();
    qDebug()<<ui->comboBox->findText("444");
}

void Widget::slotFontComboBoxcurrentIndexChanged(const QFont &font)
{
    
    
    qDebug()<<font;
    qDebug()<<ui->fontComboBox->currentIndex();
    qDebug()<<ui->fontComboBox->currentText();
}

void Widget::slotSearchLineEdit(bool)
{
    
    

    qDebug()<<ui->searchLineEdit->text();
}

void Widget::on_lineEdit_cursorPositionChanged(int arg1, int arg2)
{
    
    
    qDebug()<<"on_lineEdit_cursorPositionChanged";
}

void Widget::on_lineEdit_editingFinished()
{
    
    
    qDebug()<<"on_lineEdit_editingFinished";
}

void Widget::on_lineEdit_returnPressed()
{
    
    
    qDebug()<<"on_lineEdit_returnPressed";
    qDebug()<<ui->lineEdit->text();
}

void Widget::on_lineEdit_selectionChanged()
{
    
    
    qDebug()<<"on_lineEdit_selectionChanged";
}

void Widget::on_lineEdit_textChanged(const QString &arg1)
{
    
    
    qDebug()<<"on_lineEdit_cursorPositionChanged";
}

void Widget::on_lineEdit_textEdited(const QString &arg1)
{
    
    
    qDebug()<<"on_lineEdit_textEdited";
}

void Widget::on_textEdit_undoAvailable(bool b)
{
    
    
      qDebug()<<"on_textEdit_undoAvailable";
}

void Widget::on_textEdit_copyAvailable(bool b)
{
    
    
      qDebug()<<"on_textEdit_copyAvailable";
}

void Widget::on_spinBox_editingFinished()
{
    
    
       qDebug()<<"on_spinBox_editingFinished";
}

void Widget::on_spinBox_valueChanged(const QString &arg1)
{
    
    
       qDebug()<<"on_spinBox_valueChanged"<<arg1;
}

void Widget::on_spinBox_valueChanged(int arg1)
{
    
    
       qDebug()<<"on_spinBox_valueChanged"<<arg1;

}

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

namespace Ui {
    
    
class Widget;
}

class Widget : public QWidget
{
    
    
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
    void initSearchLineEdit();
private:
    Ui::Widget *ui;
    void initComboBox();
private slots:
    void slotComboBoxcurrentIndexChanged(int index);
    void slotFontComboBoxcurrentIndexChanged(const QFont & font);\
    void slotSearchLineEdit(bool );
    void on_lineEdit_cursorPositionChanged(int arg1, int arg2);
    void on_lineEdit_editingFinished();
    void on_lineEdit_returnPressed();
    void on_lineEdit_selectionChanged();
    void on_lineEdit_textChanged(const QString &arg1);
    void on_lineEdit_textEdited(const QString &arg1);
    void on_textEdit_undoAvailable(bool b);
    void on_textEdit_copyAvailable(bool b);
    void on_spinBox_editingFinished();
    void on_spinBox_valueChanged(const QString &arg1);
    void on_spinBox_valueChanged(int arg1);
};

#endif // WIDGET_H

猜你喜欢

转载自blog.csdn.net/weixin_44972129/article/details/109773015

相关文章