#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QComboBox>
#include <QVBoxLayout>
#include <QIcon>
int main(int argc, char**argv)
{
QApplication app(argc, argv);
QWidget *widget = new QWidget;
widget->setWindowTitle("Combox");
widget->resize(300,200);
QComboBox *combox = new QComboBox;
combox->setEditable(true);
combox->setIconSize(QSize(100, 20));
combox->insertItem(0,QIcon("Resources/images/line_solid.png"),"");
combox->insertItem(1,QIcon("Resources/images/line_dashed.png"),"");
combox->insertItem(2,QIcon("Resources/images/line_dash_dot.png"),"");
combox->insertItem(3,QIcon("Resources/images/line_dash_dot_dot.png"),"");
combox->insertItem(4,QIcon("Resources/images/line_dotted.png"),"");
QLabel *label = new QLabel("QCombox");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(combox); layout->addWidget(label);
QObject::connect(combox,SIGNAL(activated(QString)),label, SLOT(setText(QString)));
widget->setLayout(layout);
widget->show();
return app.exec();
}
效果:
QCombox添加QIcon并设置其大小
最新推荐文章于 2024-03-27 15:57:00 发布