简体   繁体   English

QTableWidget与其父QWidget的边界对齐

[英]QTableWidget alignement with the borders of its parent QWidget

Let's consider we have QWidget that contains QTableWidget (only). 考虑一下我们有包含QTableWidget的QWidget(仅)。 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. 因此,我们想通过调整窗口小部件的大小来调整表的大小,并且我们不想在QWidget边框和表的单元格之间有一个indet。 What kind of property is making posible for QTableWidget to be aligned with the borders of it parent widget? 什么样的属性才可能使QTableWidget与其父窗口小部件的边界对齐?

Thanks. 谢谢。

First, you want to make sure the QTableWidget is placed inside a layout. 首先,您要确保QTableWidget放置在布局内。 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 . 假设parent_widget已经指向包含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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM