How can I add resizable widgets in Qt Creator?

后端 未结 2 1113
时光说笑
时光说笑 2021-01-15 19:05

How can I add resizable widgets in Qt Creator?

Specially widgets in QVBoxLayout or QHBoxLayout

相关标签:
2条回答
  • 2021-01-15 19:33

    Example:

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QWidget* w = new QWidget;
        QVBoxLayout* l = new QVBoxLayout;
        w->setLayout(l);
        QPushButton* b = new QPushButton("hello");
        b->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
        l->addWidget(b);
        w->show();    
    
        return app.exec();
    }
    
    0 讨论(0)
  • 2021-01-15 19:46

    You must use layouts if you want that your widgets are resizable: http://doc.qt.io/qt-5/layout.html

    0 讨论(0)
提交回复
热议问题