开发者

QTableWidget alignement with the borders of its parent QWidget

开发者 https://www.devze.com 2022-12-24 13:51 出处:网络
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 QWidge开发者_Go百科t border and

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 QWidge开发者_Go百科t 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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消