14

我有一个复杂的对话框,它充满了空格,我无法缩小它。在 Designer 中,它有很多组件会被动态隐藏,还有一些是动态添加的。我添加了尺寸策略、尺寸提示和最小尺寸的倾倒,但仍然无法弄清楚为什么 Qt 不允许我将其拖得更小。

必须有一些工具或技术来解决这个问题。

请分享。

4

5 回答 5

4

我不知道有什么工具可以做到这一点,但我之前通过更改对话框中不同元素的调色板来管理它,然后查看占用比我预期更多(或更少)的空间,并专注于我的对这些要素进行调查。

在更一般的意义上,确保您已将对话框设置为不固定大小。那也咬了我一次。

于 2008-10-24T15:20:47.653 回答
3

您可以捕获 QApplication::focusChanged(QWidget*,QWidget*) 信号并更改当前聚焦小部件的背景。我认为这将有助于确定每个小部件占用多少空间。

于 2011-03-18T20:45:48.107 回答
1

听起来我们可以使用相当于 Firebug 的元素和 CSS 指标检查器模式。这种工具最难的部分将是有效地弄清楚和沟通为什么单个布局策略在小部件中使用或不使用给定的大小值。

于 2008-11-03T21:10:11.097 回答
1

It's hard to tell without seeing your layout, but I see a lot of resize problems like you describe due to using QGridLayout. The largest thing in a column or row, is going to determine the minimum width of that column. The same for a row.

If you are using QGridLayout, you might try making things span columns/rows.

I'd also recommend trying all your various layout configurations in Designer and test it by resizing. We don't actually use Designer where I work, but I use it all the time to test, and debug layout ideas.

于 2008-12-11T01:28:41.367 回答
0

大量的试验和错误。我发现在关键位置插入拉伸通常可以帮助我产生我想要的效果。例如,如果我在布局中有一个 QPushButton,我想成为最小尺寸,我将执行以下操作:


QHBoxLayout* layout = new QHBoxLayout;
QPushButton* myBtn = new QPushButton("Test");

layout->insertStretch(1);
layout->addWidget(myBtn, 0);
layout->insertStretch(1);

另外,不要忘记您可以使用 setContentsMargins() 设置布局的内容边距。

我不使用 Designer,因为我发现当我在代码中使用它时,我对布局系统的理解要好得多。

于 2011-03-18T20:52:20.767 回答