質問編集履歴
2
暫定処置があったので追記した。
title
CHANGED
File without changes
|
body
CHANGED
@@ -81,4 +81,18 @@
|
|
81
81
|
|
82
82
|
https://gist.github.com/tacchang001/f8b4287020d30b3b5d8f6fc96a639963
|
83
83
|
|
84
|
+
### 検討中
|
85
|
+
|
86
|
+
#### 2021/11/28 主レイアウトの最小高をSubPanelに設定してみた
|
87
|
+
|
88
|
+
ウィジェットやレイアウトのSizeやHintSizeを表示してみて、やっぱりというかSubPanel(QPushButtonとQTableWidgetのまとめ役)の高さが妙な高さ(というか私がよく分かっていない)であるため、見た目が妙な間延びで表示されているところまでは分かりました。
|
89
|
+
|
90
|
+
解決方法は分かっていませんが、期待に一番近いのはSubPanelの主パネルが示してくれる最小高をSubPanelの高さに指定する方法です。
|
91
|
+
|
92
|
+
```c++
|
93
|
+
setFixedHeight(layout->totalMinimumSize().height());
|
94
|
+
```
|
95
|
+
|
96
|
+
これが最適解かどうかはわかりませんが、少なくとも見た目は期待通りになりました。
|
97
|
+
|
84
98
|
以上
|
1
ソース全体はGithub Gistに置いた。
title
CHANGED
File without changes
|
body
CHANGED
@@ -75,228 +75,10 @@
|
|
75
75
|
|
76
76
|
```
|
77
77
|
|
78
|
-
### ソース全体
|
78
|
+
### ソース全体
|
79
79
|
|
80
|
-
```c++
|
81
|
-
|
80
|
+
ソース全体はGithub Gistに載せておきます。
|
82
|
-
QWidget(parent)
|
83
|
-
{
|
84
81
|
|
85
|
-
auto mainLayout = new QVBoxLayout(this);
|
86
|
-
{
|
87
|
-
auto layoutTop = new QHBoxLayout;
|
88
|
-
{
|
89
|
-
|
82
|
+
https://gist.github.com/tacchang001/f8b4287020d30b3b5d8f6fc96a639963
|
90
|
-
layoutTop->addWidget(button);
|
91
83
|
|
92
|
-
auto comboBox = new QComboBox(this);
|
93
|
-
layoutTop->addWidget(comboBox);
|
94
|
-
}
|
95
|
-
mainLayout->addLayout(layoutTop);
|
96
|
-
|
97
|
-
auto layoutMiddle = new QHBoxLayout;
|
98
|
-
{
|
99
|
-
auto layoutLeft = new QVBoxLayout;
|
100
|
-
{
|
101
|
-
auto button = new QPushButton("middle left", this);
|
102
|
-
layoutLeft->addWidget(button);
|
103
|
-
|
104
|
-
auto group1 = new QGroupBox("GroupBox 1");
|
105
|
-
{
|
106
|
-
auto layout = new QVBoxLayout;
|
107
|
-
{
|
108
|
-
auto button1 = new QPushButton("middle left groupbox1", this);
|
109
|
-
layout->addWidget(button1);
|
110
|
-
}
|
111
|
-
group1->setLayout(layout);
|
112
|
-
}
|
113
|
-
layoutLeft->addWidget(group1);
|
114
|
-
|
115
|
-
auto group2 = new QGroupBox("GroupBox 2");
|
116
|
-
{
|
117
|
-
auto layout = new QVBoxLayout;
|
118
|
-
{
|
119
|
-
auto button1 = new QPushButton("middle left groupbox2", this);
|
120
|
-
layout->addWidget(button1);
|
121
|
-
}
|
122
|
-
group2->setLayout(layout);
|
123
|
-
}
|
124
|
-
layoutLeft->addWidget(group2);
|
125
|
-
}
|
126
|
-
layoutMiddle->addLayout(layoutLeft);
|
127
|
-
|
128
|
-
auto layoutRight = new QVBoxLayout;
|
129
|
-
{
|
130
|
-
auto button = new QPushButton("middle right", this);
|
131
|
-
layoutRight->addWidget(button);
|
132
|
-
}
|
133
|
-
layoutMiddle->addLayout(layoutRight);
|
134
|
-
}
|
135
|
-
mainLayout->addLayout(layoutMiddle);
|
136
|
-
|
137
|
-
auto layoutBottom = new QVBoxLayout;
|
138
|
-
{
|
139
|
-
auto button = new QPushButton("middle bottom", this);
|
140
|
-
layoutBottom->addWidget(button);
|
141
|
-
|
142
|
-
auto table = new QTableWidget(this);
|
143
|
-
{
|
144
|
-
table->setStyleSheet("background-color: Blue;");
|
145
|
-
table->setColumnCount(3);
|
146
|
-
table->setRowCount(3);
|
147
|
-
table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
148
|
-
table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
149
|
-
auto h = table->horizontalHeader();
|
150
|
-
h->setSectionResizeMode(0, QHeaderView::Stretch);
|
151
|
-
h->setSectionResizeMode(1, QHeaderView::Stretch);
|
152
|
-
h->setSectionResizeMode(2, QHeaderView::Stretch);
|
153
|
-
table->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
154
|
-
table->resizeRowsToContents();
|
155
|
-
|
156
|
-
int nRowHeight = table->rowHeight(0);
|
157
|
-
int nTableHeight =
|
158
|
-
(table->rowCount() * nRowHeight) +
|
159
|
-
table->horizontalHeader()->height() +
|
160
|
-
2 * table->frameWidth();
|
161
|
-
table->setMinimumHeight(nTableHeight);
|
162
|
-
table->setMaximumHeight(nTableHeight);
|
163
|
-
}
|
164
|
-
layoutBottom->addWidget(table);
|
165
|
-
}
|
166
|
-
mainLayout->addLayout(layoutBottom);
|
167
|
-
|
168
|
-
setLayout(mainLayout);
|
169
|
-
|
170
|
-
mainLayout->addStretch();
|
171
|
-
}
|
172
|
-
|
173
|
-
adjustSize();
|
174
|
-
}
|
175
|
-
|
176
|
-
```
|
177
|
-
|
178
|
-
### ソース全体(QWidgetでまとめるケース)
|
179
|
-
|
180
|
-
```c++
|
181
|
-
MainWindow::MainWindow(QWidget *parent) :
|
182
|
-
QWidget(parent)
|
183
|
-
{
|
184
|
-
|
185
|
-
auto mainLayout = new QVBoxLayout(this);
|
186
|
-
{
|
187
|
-
auto layoutTop = new QHBoxLayout;
|
188
|
-
{
|
189
|
-
auto button = new QPushButton("top", this);
|
190
|
-
layoutTop->addWidget(button);
|
191
|
-
|
192
|
-
auto comboBox = new QComboBox(this);
|
193
|
-
layoutTop->addWidget(comboBox);
|
194
|
-
}
|
195
|
-
mainLayout->addLayout(layoutTop);
|
196
|
-
|
197
|
-
auto layoutMiddle = new QHBoxLayout;
|
198
|
-
{
|
199
|
-
auto layoutLeft = new QVBoxLayout;
|
200
|
-
{
|
201
|
-
auto button = new QPushButton("middle left", this);
|
202
|
-
layoutLeft->addWidget(button);
|
203
|
-
|
204
|
-
auto group1 = new QGroupBox("GroupBox 1");
|
205
|
-
{
|
206
|
-
auto layout = new QVBoxLayout;
|
207
|
-
{
|
208
|
-
auto button1 = new QPushButton("middle left groupbox1", this);
|
209
|
-
layout->addWidget(button1);
|
210
|
-
}
|
211
|
-
group1->setLayout(layout);
|
212
|
-
}
|
213
|
-
layoutLeft->addWidget(group1);
|
214
|
-
|
215
|
-
auto group2 = new QGroupBox("GroupBox 2");
|
216
|
-
{
|
217
|
-
auto layout = new QVBoxLayout;
|
218
|
-
{
|
219
|
-
auto button1 = new QPushButton("middle left groupbox2", this);
|
220
|
-
layout->addWidget(button1);
|
221
|
-
}
|
222
|
-
group2->setLayout(layout);
|
223
|
-
}
|
224
|
-
layoutLeft->addWidget(group2);
|
225
|
-
}
|
226
|
-
layoutMiddle->addLayout(layoutLeft);
|
227
|
-
|
228
|
-
auto layoutRight = new QVBoxLayout;
|
229
|
-
{
|
230
|
-
auto button = new QPushButton("middle right", this);
|
231
|
-
layoutRight->addWidget(button);
|
232
|
-
}
|
233
|
-
layoutMiddle->addLayout(layoutRight);
|
234
|
-
}
|
235
|
-
mainLayout->addLayout(layoutMiddle);
|
236
|
-
|
237
|
-
auto layoutBottom = new QVBoxLayout;
|
238
|
-
{
|
239
|
-
auto sub = new SubPanel(this);
|
240
|
-
layoutBottom->addWidget(sub, 0, Qt::AlignTop);
|
241
|
-
|
242
|
-
layoutBottom->setSizeConstraint(QLayout::SetFixedSize);
|
243
|
-
}
|
244
|
-
mainLayout->addLayout(layoutBottom);
|
245
|
-
|
246
|
-
setLayout(mainLayout);
|
247
|
-
|
248
|
-
mainLayout->addStretch();
|
249
|
-
}
|
250
|
-
|
251
|
-
adjustSize();
|
252
|
-
}
|
253
|
-
|
254
|
-
|
255
|
-
```
|
256
|
-
|
257
|
-
```c++
|
258
|
-
SubPanel::SubPanel(QWidget *parent)
|
259
|
-
: AbstractPanel(parent)
|
260
|
-
{
|
261
|
-
auto layout = new QVBoxLayout(this);
|
262
|
-
{
|
263
|
-
auto button = new QPushButton("middle bottom", this);
|
264
|
-
layout->addWidget(button, 1, Qt::AlignTop);
|
265
|
-
|
266
|
-
auto table = new QTableWidget(this);
|
267
|
-
{
|
268
|
-
table->setStyleSheet("background-color: Blue;");
|
269
|
-
table->setColumnCount(3);
|
270
|
-
table->setRowCount(3);
|
271
|
-
table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
272
|
-
table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
273
|
-
auto h = table->horizontalHeader();
|
274
|
-
h->setSectionResizeMode(0, QHeaderView::Stretch);
|
275
|
-
h->setSectionResizeMode(1, QHeaderView::Stretch);
|
276
|
-
h->setSectionResizeMode(2, QHeaderView::Stretch);
|
277
|
-
table->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
278
|
-
table->resizeRowsToContents();
|
279
|
-
|
280
|
-
int nRowHeight = table->rowHeight(0);
|
281
|
-
int nTableHeight =
|
282
|
-
(table->rowCount() * nRowHeight) +
|
283
|
-
table->horizontalHeader()->height() +
|
284
|
-
2 * table->frameWidth();
|
285
|
-
table->setMinimumHeight(nTableHeight);
|
286
|
-
table->setMaximumHeight(nTableHeight);
|
287
|
-
}
|
288
|
-
layout->addWidget(table, 1, Qt::AlignTop);
|
289
|
-
}
|
290
|
-
|
291
|
-
setLayout(layout);
|
292
|
-
|
293
|
-
// layout->setSizeConstraint(QLayout::SetFixedSize);
|
294
|
-
|
295
|
-
// setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
296
|
-
}
|
297
|
-
|
298
|
-
```
|
299
|
-
|
300
|
-
|
301
|
-
|
302
84
|
以上
|