Question

I have QTableWidget and I have populated one column with .svg files with QSvgWidget to show them :

for...
    svgWidget = QSvgWidget("C:\mySVG.svg")
    self.ui.tableWidget.setCellWidget(i, j, svgWidget)
...

Other columns are populated with some text, and the problem occurs when I try to use

self.ui.tableWidget.resizeRowsToContents()

svgWidget is being stretched (I need preserved aspect ratio)... So, I set max size with svgWidget.setMaximumSize(svgWidget.sizeHint()) and now height of every row is set to height of svgWidget in that row, so if there is more text it is being cut, but I can stretch height of any row manually to see text, white space is added in cell with svgWidget, as I expected. My question is why resizeRowsToContents() didn't do the job (why white space can't be added automatically?). Examples would be appreciated, I've googled this out, there is lack of examples.

Was it helpful?

Solution

I've solved it like this:

self.ui.tableWidget.setSortingEnabled(0)
...populating table columns with text and svgWidgets....
self.ui.tableWidget.setSortingEnabled(1)
self.ui.tableWidget.horizontalHeader().sortIndicatorChanged.connect(self.ui.tableWidget.resizeRowsToContents)

for some reason any other order won't work for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top