QTableWidget 与其父 QWidget 的边框对齐

发布于 2024-08-26 20:39:06 字数 148 浏览 4 评论 0原文

假设我们有一个包含 QTableWidget(仅)的 QWidget。因此,我们希望通过调整小部件的大小来调整表格的大小,并且我们不希望在 QWidget 边框和表格单元格之间有缩进。什么样的属性可以使 QTableWidget 与其父窗口小部件的边框对齐?

谢谢。

Let's consider we have QWidget that contains QTableWidget (only). So we want to resize the table by resizing the widget, and we dont want to have an indet between the QWidget border and cells of the table. What kind of property is making posible for QTableWidget to be aligned with the borders of it parent widget?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事灯 2024-09-02 20:39:06

首先,您要确保将 QTableWidget 放置在布局内。例如,

QTableWidget* tw = new QTableWidget(parent_widget);
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(tw);
parent_widget->setLayout(layout);

假设 parent_widget 已经指向包含 QTableWidget 的小部件。这将确保当父窗口小部件调整表大小时。要让表格填充小部件的整个空间,只需在布局上将边距设置为零即可。尝试以下其中一项:

layout->setMargin(0);

layout->setContentsMargins(0,0,0,0);

First, you want to make sure the QTableWidget is placed inside a layout. For instance,

QTableWidget* tw = new QTableWidget(parent_widget);
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(tw);
parent_widget->setLayout(layout);

assuming parent_widget is already pointing to the widget containing the QTableWidget. This will ensure that the table resizes when the parent widget does. To have the table fill the entire space of the widget, just set the margin to zero on the layout. Try one of these:

layout->setMargin(0);

or

layout->setContentsMargins(0,0,0,0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文