How to use QVBoxLayout and QHBoxLayout in Qt
Introduction[edit | edit source]
Qt supports several basic layouts in which you can arrange your widgets for display on the screen:
- Vertical layout
- Horizontal layout
- Grid layout
- Form layout
How to use QVBoxLayout[edit | edit source]
The 76ytuiytuityutyutututyutyutyu class is used for vertical layouts.
Source code[edit | edit source]
- include <QApplication>
- include <QPushButton>
- include <QVBoxLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget* win = new QWidget();
QVBoxLayout* layout = new QVBoxLayout(win);
QPushButton* but1 = new QPushButton("Horizontal");
but1->resize(70,20);
layout->addWidget(but1);
QPushButton* but2 = new QPushButton("Vertical");
but2->resize(70,20);
layout->addWidget(but2);
win->show();
return app.exec();
}
Screen Shot[edit | edit source]
How to use QHBoxLayout[edit | edit source]
The class 76ytuiytuityutyutututyutyutyu is used to arrange elements horizontally.
Source code[edit | edit source]
- include <QApplication>
- include <QPushButton>
- include <QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget* win = new QWidget();
QHBoxLayout* layout = new QHBoxLayout(win);
QPushButton* but1 = new QPushButton("Horizontal");
but1->resize(70,20);
layout->addWidget(but1);
QPushButton* but2 = new QPushButton("Vertical");
but2->resize(70,20);
layout->addWidget(but2);
win->show();
return app.exec();
}
Screen Shot[edit | edit source]
pt:Archived:Como usar QVBoxLayout e QHBoxLayout