Инструменты пользователя

Инструменты сайта


develop:qt:gui

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
develop:qt:gui [2021/09/28 06:22]
admin
develop:qt:gui [2021/09/28 07:49] (текущий)
admin
Строка 4: Строка 4:
 ===== Расположение элементов ===== ===== Расположение элементов =====
 ----- -----
-**QBoxLayout**, **QVBoxLayout**, **QHBoxLayout**, **QGridLayout**.\\+**QBoxLayout**, **QVBoxLayout**, **QHBoxLayout**, **QGridLayout**. Вертикальная, горизонтальная, так же есть компоновка сеткой.\\
  
-Вертикальная, горизонтальная компоновка, так же есть компоновка сеткой.\\+<details> 
 +<summary>:!: Примериспользование горизонтальной и вертикальной компоновок</summary> 
 +{{:develop:qt:lay_hv.png?direct&400|}}  
 +<code cpp-qt> 
 +/*...*/ 
 +    labComboCapt= new QLabel("Выберите хост", this); 
 +    comboHostServ= new QComboBox(this); 
 +    comboHostServ->addItem(QHostAddress(QHostAddress::LocalHost).toString()); 
 +    QHBoxLayout *layFirstRow= new QHBoxLayout(); 
 +    layFirstRow->addWidget(labComboCapt); 
 +    layFirstRow->addWidget(comboHostServ, 1);
  
 +    labEditCapt= new QLabel("Укажите порт", this);
 +    editPortServ= new QLineEdit(this);
 +    editPortServ->setText("2233");
 +    QHBoxLayout *layDoubleRow= new QHBoxLayout();
 +    layDoubleRow->addWidget(labEditCapt);
 +    layDoubleRow->addWidget(editPortServ, 1);
  
 +    labStatus= new QLabel("Здесь будет статус", this);
  
 +    butGetFortune= new QPushButton("Get Fort", this);
 +    butQuit= new QPushButton("Quit", this);
 +    QHBoxLayout *layButtsRow= new QHBoxLayout();
 +    layButtsRow->addStretch(1);
 +    layButtsRow->addWidget(butGetFortune, 1);
 +    layButtsRow->addWidget(butQuit, 1);
  
-=====  ===== +    QVBoxLayout *layMainnew QVBoxLayout(this); 
------+    layMain->addLayout(layFirstRow); 
 +    layMain->addLayout(layDoubleRow); 
 +    layMain->addWidget(labStatus, 0, Qt::AlignHCenter); 
 +    layMain->addLayout(layButtsRow); 
 +/*...*/ 
 +</code> 
 +</details>
  
  
 +<details>
 +<summary>:!: Пример: тоже самое только сеткой</summary>
 +{{:develop:qt:lay_grid.png?direct&400|}}\\
 +* При добавлении указываются координаты ячейки и кол-во занимаемых ей строк/столбцов (-1 значит до конца)
 +<code cpp-qt>
 +/*...*/
 +    labComboCapt= new QLabel("Выберите хост", this);
 +    comboHostServ= new QComboBox(this);
 +    comboHostServ->addItem(QHostAddress(QHostAddress::LocalHost).toString());
  
-=====  ===== +    labEditCaptnew QLabel("Укажите порт", this); 
------+    editPortServnew QLineEdit(this); 
 +    editPortServ->setText("2233");
  
 +    labStatus= new QLabel("Здесь будет статус", this);
  
-=====  ===== +    butGetFortunenew QPushButton("Get Fort", this); 
------+    butQuitnew QPushButton("Quit", this); 
 +     
 +    QGridLayout *layMainGridnew QGridLayout(this); 
 +    layMainGrid->addWidget(labComboCapt, 0, 0); 
 +    layMainGrid->addWidget(comboHostServ, 0, 1, 1, -1);
  
 +    layMainGrid->addWidget(labEditCapt, 1, 0);
 +    layMainGrid->addWidget(editPortServ, 1, 1, 1, -1);
  
-=====  ===== +    layMainGrid->addWidget(labStatus, 2, 0, 1, -1, Qt::AlignCenter);
------+
  
 +    layMainGrid->addWidget(butGetFortune, 3, 1);
 +    layMainGrid->addWidget(butQuit, 3, 2);
  
 +    layMainGrid->setColumnStretch(1, 1);
 +    layMainGrid->setColumnStretch(2, 1);
 +/*...*/
 +</code>
 +</details>
 +
 +В сетке **QLabel автоматом заполняет всю высоту**. И расстояние увеличивается пропорционально при увеличении размеров формы, а остальные строки "прижимаются" к краям.\\
 +<details>
 +<summary>:!: Пример: Непонятное поведение при заполнении сетки.</summary>
 +{{:develop:qt:lay_def1.png?direct&400|}} {{:develop:qt:lay_def2.png?direct&400|}}\\
 +**В первом случае** однотипные строки\\
 +<code cpp-qt>
 +/*...*/
 +    QGridLayout *layMainGrid= new QGridLayout(this);
 +    layMainGrid->setColumnStretch(1, 1);
 +    layMainGrid->setColumnStretch(2, 1);
 +
 +    labComboCapt= new QLabel("Выберите хост", this);
 +    comboHostServ= new QComboBox(this);
 +    comboHostServ->addItem(QHostAddress(QHostAddress::LocalHost).toString());
 +    layMainGrid->addWidget(labComboCapt, 0, 0);
 +    layMainGrid->addWidget(comboHostServ, 0, 1, 1, -1);
 +
 +    labEditCapt= new QLabel("Укажите порт", this);
 +    editPortServ= new QLineEdit(this);
 +    editPortServ->setText("2233");
 +    layMainGrid->addWidget(labEditCapt, 1, 0);
 +    layMainGrid->addWidget(editPortServ, 1, 1, 1, -1);
 +
 +    QLabel *labEditCapt2= new QLabel("Укажите порт2", this);
 +    QLineEdit *editPortServ2= new QLineEdit(this);
 +    layMainGrid->addWidget(labEditCapt2, 2, 0);
 +    layMainGrid->addWidget(editPortServ2, 2, 1, 1, -1);
 +
 +    butGetFortune= new QPushButton("Get Fort", this);
 +    butQuit= new QPushButton("Quit", this);
 +    layMainGrid->addWidget(butGetFortune, 4, 1);
 +    layMainGrid->addWidget(butQuit, 4, 2);
 +/*...*/    
 +</code>
 +
 +**Во втором** добавлены лейблы внизу, они автоматом начинают занимать все свободное пространство\\
 +<code cpp-qt>
 +/*...*/    
 +    QGridLayout *layMainGrid= new QGridLayout(this);
 +    layMainGrid->setColumnStretch(1, 1);
 +    layMainGrid->setColumnStretch(2, 1);
 +
 +    labComboCapt= new QLabel("Выберите хост", this);
 +    comboHostServ= new QComboBox(this);
 +    comboHostServ->addItem(QHostAddress(QHostAddress::LocalHost).toString());
 +    layMainGrid->addWidget(labComboCapt, 0, 0);
 +    layMainGrid->addWidget(comboHostServ, 0, 1, 1, -1);
 +
 +    labEditCapt= new QLabel("Укажите порт", this);
 +    editPortServ= new QLineEdit(this);
 +    editPortServ->setText("2233");
 +    layMainGrid->addWidget(labEditCapt, 1, 0);
 +    layMainGrid->addWidget(editPortServ, 1, 1, 1, -1);
 +
 +    labStatus= new QLabel("Здесь будет статус", this);
 +    layMainGrid->addWidget(labStatus, 2, 0);
 +    QLabel *labOver= new QLabel("This is overall label about suka layout");
 +    layMainGrid->addWidget(labOver, 2, 1, 1, -1);
 +
 +    butGetFortune= new QPushButton("Get Fort", this);
 +    butQuit= new QPushButton("Quit", this);
 +    layMainGrid->addWidget(butGetFortune, 4, 1);
 +    layMainGrid->addWidget(butQuit, 4, 2);
 +/*...*/
 +</code>
 +</details>
 +
 +
 +
 +
 +
 +
 +=====  =====
 +-----
  
 <details> <details>
develop/qt/gui.1632810152.txt.gz · Последнее изменение: 2021/09/28 06:22 — admin