https://github.com/imane0x/fun_with_layouts
https://github.com/imane0x/fun_with_layouts
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/imane0x/fun_with_layouts
- Owner: imane0x
- Created: 2021-11-04T20:39:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-07T15:23:09.000Z (over 3 years ago)
- Last Synced: 2025-01-27T08:42:48.980Z (5 months ago)
- Language: C++
- Size: 159 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Fun_With_Layouts
The goal of this lab is learn to analyse the construction of a form and then code it using Netsted layouts.## Nested Layouts:

First let´s create the components and the layouts :
``` cpp
QLineEdit* name ;
QPushButton* search;
QPushButton* close;
QCheckBox* match;
QCheckBox* search_b;
auto main_layout = new QHBoxLayout;
auto left_layout = new QVBoxLayout;
auto right_layout = new QVBoxLayout;
auto Top_left_layout = new QFormLayout;
```
Then,let´s add the components in the layouts and add the layouts in the main one:
``` cpp
Top_left_layout->addRow("name:", name);
right_layout->addWidget(search);
left_layout->addLayout(Top_left_layout);
main_layout->addLayout(left_layout);
```
Now, let's connect the close button:
``` cpp
connect(close, &QPushButton::clicked, qApp, &QApplication::exit);
```
Finally,let´s add strech to the layouts:
``` cpp
right_layout->addStretch(10);
```
Here is the result:
## Bug Report Form:
First let´s create the components and the layouts :
``` cpp
QLineEdit* name ;
QLineEdit *company;
QLineEdit *phone;
QLineEdit *email;
QLineEdit *problem_title;
QTextEdit *summary;
QComboBox *list ;
QPushButton* reset;
QPushButton* submit;
QPushButton* n_submit;
auto main_layout = new QVBoxLayout;
auto down_layout = new QHBoxLayout;
auto layout_ = new QFormLayout;
```
Then let´s add the components in the layouts and add the layouts in the main one:
``` cpp
layout_->addRow("Name:",name);
layout_->addRow("Comany:",company);
layout_->addRow("Phone:",phone);
layout_->addRow("Email:",email);
layout_->addRow("Problem Title:",problem_title);
layout_->addRow("Summary:",summary);
list->addItem("Always");
layout_->addRow("Reproductibility:",list);
down_layout->addWidget(reset);
down_layout->addStretch(10);
down_layout->addWidget(submit);
down_layout->addWidget(n_submit);
main_layout->addLayout(layout_);
main_layout->addLayout(down_layout);```
Then let´s add the strech:
``` cpp
down_layout->addStretch(20);
```
Here is the result:
## Calculator:First let´s create the components and the layouts :
``` cpp
QGridLayout *grid_layout;
QVBoxLayout* layout ;
QVector nums { "9", "8", "7","/","6", "5", "4","*","3", "2", "1","0","+", "-", ".", "=" };
QLCDNumber* lcd;
```
Then let´s add the components in the layouts and add the layouts in the main one:
``` cpp
layout->addWidget(lcd);
layout->addLayout(grid_layout);int pos = 0;
for (int i=0; i<4; i++) {
for (int j=0; j<4; j++) {auto *button = new QPushButton(nums[pos], this);
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
grid_layout->addWidget(button, i, j);
pos++;
}
}
setLayout(layout);
```
Here is the result: