[Qt练习]pushButton 外观

 

#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QMenu>
#include <QVBoxLayout>

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);
    QWidget *window = new QWidget;
    window->setWindowTitle("QPushbutton");
    window->resize(300,50);

    //Normal Button
    QPushButton *btnNormal = new QPushButton("Normal Button");

    //Toggle Button 开关按钮
    QPushButton *btnToggle = new QPushButton("Toggle Button");
    btnToggle->setCheckable(true);
    btnToggle->setChecked(true);

    //flat Button
    QPushButton *btnFlat = new QPushButton("Flat Button");

    //Popup Button
    QPushButton *btnPopup = new QPushButton("Popup Button");
    QMenu * menu = new QMenu;
    menu->addAction("Open");
    menu->addAction("Save");
    menu->addMenu("More");
    menu->addSeparator();
    menu->addAction("close");
    btnPopup->setMenu(menu);

    //layout
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(btnNormal);
    layout->addWidget(btnToggle);
    layout->addWidget(btnFlat);
    layout->addWidget(btnPopup);

    layout->addStretch(1);
    window->setLayout(layout);
    window->show();
    return app.exec();
}

运行结果

[Qt练习]pushButton 外观_第1张图片

 

按下 开关按钮

 

按下菜单按钮

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