[Qt练习]QCombox

 

#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->insertItem(0,QIcon("1.jpg"),"1");
    combox->insertItem(1,QIcon("2.jpg"),"2");
    combox->insertItem(2,QIcon("3.png"),"3");
    combox->insertItem(3,QIcon("4.png"),"4");

    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();
}


 

 

 

 

你可能感兴趣的:(layout,qt,include,Signal)