QT QPushButton

时间:2023-03-08 22:37:48
#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(, );

 QPushButton *btn1 = new QPushButton("NOrmal Button");    

QPushButton *btn2 = new QPushButton("Toggle Button");    

btn2->setCheckable(true);    

btn2->setChecked(true);

QPushButton *btn3 = new QPushButton("Flat Button");    

btn3->setFlat(true);

QPushButton *btn4 = new QPushButton("Popup Button");    

QMenu *menu = new QMenu;    

menu->addAction("Open Item");    

menu->addAction("Save Item");    

menu->addAction("More Item");    

menu->addSeparator();    

menu->addAction("Close Item");    

btn4->setMenu(menu);

QVBoxLayout *layout = new QVBoxLayout;    

layout->addWidget(btn1);    

layout->addWidget(btn2);    

layout->addWidget(btn3);    

layout->addWidget(btn4);    

layout->addStretch();

window->setLayout(layout);    

window->show();

return app.exec();

}