I tried to insert some QRadioButton inside some cell of a QTableWidget. The situation is similar to the one of this post. In particular, the solution by @eyllanesc, with PySide2
is the following
import sys
from PySide2.QtWidgets import QApplication, QTableWidget, QTableWidgetItem, \
QButtonGroup, QRadioButton
app = QApplication(sys.argv)
searchView = QTableWidget(0, 4)
colsNames = ['A', 'B', 'C']
searchView.setHorizontalHeaderLabels(['DIR'] + colsNames)
dirNames = {'A': ['/tmp', '/tmp/dir1'], 'B': ['/tmp/dir2'],
'C': ['/tmp/dir3']}
rowCount = sum(len(v) for (name, v) in dirNames.items())
searchView.setRowCount(rowCount)
index = 0
for letter, paths in dirNames.items():
for path in paths:
it = QTableWidgetItem(path)
searchView.setItem(index, 0, it)
group = QButtonGroup(searchView)
for i, name in enumerate(colsNames):
button = QRadioButton()
group.addButton(button)
searchView.setCellWidget(index, i + 1, button)
if name == letter:
button.setChecked(True)
index += 1
searchView.show()
sys.exit(app.exec_())
When resizing the columns or rows, I notice a weird behavior: while I'm pressing the mouse button and resizing the column or the raw, the QRadioButtons remain still at their places, causing some clashes; then, when I finally release the mouse button, every QRadioButton come to its place. Is there a way to avoid that aka to make the QRadioButtons move as well during the resizing process?