QCombox添加QIcon并设置其大小

来源:互联网 发布:淘宝店被工商局找上门 编辑:程序博客网 时间:2024/04/29 22:41
#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();}
效果:
原创粉丝点击