开发者

How can I add resizable widgets in Qt Creator?

How can I add resizable widget开发者_StackOverflow中文版s in Qt Creator?

Specially widgets in QVBoxLayout or QHBoxLayout


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜