【发布时间】:2021-09-26 17:25:35
【问题描述】:
我有一个QTableWidget,还有一个QLabel,我使用.setCellWidget() 将其放入表格的单元格中。
在运行时,我更改了 QLabel 所在的QTableWidget 单元格的跨度,使用.setSpan()
但是当我更改QLabel 所在单元格的跨度时,QLabel 不会调整大小。
一些代码和截图如下:
def generate_table(self):
global gtable
table = QTableWidget(20, 60)
gtable = table
def create_task(self):
task_widget = QWidget()
task_layout = QHBoxLayout()
task_widget.setLayout(task_layout)
task = QLabelClickable(the_task_name)
task_layout.addWidget(task)
gtable.setCellWidget(selected_row_column[0], selected_row_column[1], task_widget)
// if I include this part of the code, everything looks fine, both cell, widget and label scale properly, as visible through background color, below line is not the problem, notice its in the same function as where I set the cell widget
the_duration = 3
gtable.setSpan(selected_row, selected_column, 1, the_duration)
// Below is how I change the cell span. The rrow and ccolumn are integers, basically just cell coordinates
def save_task(self):
gtable.setSpan(rrow, ccolumn, 1, w_dr.value())
(到处都有大量代码,所以我包含了我认为相关的内容,让我知道我应该包含代码的其他部分)
它应该是这样的:(这是第一条跨度更改行所做的)
这就是它的样子:(这是最后一行的作用)
我的问题是,如何调整 QLabel / QWidget 的大小以自动适应单元格的更新大小?
【问题讨论】: