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

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


develop:qt:gui

Различия

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

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

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
develop:qt:gui [2021/09/28 06:34]
admin
develop:qt:gui [2021/09/28 07:49] (текущий)
admin
Строка 4: Строка 4:
 ===== Расположение элементов ===== ===== Расположение элементов =====
 ----- -----
-**QBoxLayout**, **QVBoxLayout**, **QHBoxLayout**, **QGridLayout**.\\ +**QBoxLayout**, **QVBoxLayout**, **QHBoxLayout**, **QGridLayout**. Вертикальная, горизонтальная, так же есть компоновка сеткой.\\
-Вертикальная, горизонтальная, так же есть компоновка сеткой.\\ +
  
 <details> <details>
 <summary>:!: Пример: использование горизонтальной и вертикальной компоновок</summary> <summary>:!: Пример: использование горизонтальной и вертикальной компоновок</summary>
-{{:develop:qt:lay_hv.png?direct&400|}}+{{:develop:qt:lay_hv.png?direct&400|}} 
 <code cpp-qt> <code cpp-qt>
 /*...*/ /*...*/
Строка 83: Строка 81:
 </details> </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);
  
-=====  ===== +    labComboCaptnew QLabel("Выберите хост", this); 
------+    comboHostServnew 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);
  
-=====  ===== +    butGetFortunenew QPushButton("Get Fort", this); 
------+    butQuitnew 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);
  
-=====  ===== +    labComboCaptnew QLabel("Выберите хост", this); 
------+    comboHostServnew 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);
  
-=====  ===== +    labStatusnew QLabel("Здесь будет статус", this); 
------+    layMainGrid->addWidget(labStatus, 2, 0); 
 +    QLabel *labOvernew 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.1632810859.txt.gz · Последнее изменение: 2021/09/28 06:34 — admin