alignment for QCheckBox in QTableWidget
-
I've created a checkbox in a cellwidget within a tablewidget. The checkbox is by default aligned left, like the image attached I can't find any documentation in QCheckBox to set alignment.
Any help? Is there some sort of spacing or padding for qtablewidget?
Thanks
cow
-
Hi and welcome to devnet,
How did you create them ?
-
I think something reproducible would be:
ccHeaders = QtWidgets.QTableWidget()
checkbox = QtWidgets.QCheckBox()
ccHeaders.setCellWidget(0, 0, checkbox) -
@Denni-0 said in alignment for QCheckBox in QTableWidget:
The alignment is not part of checkbox that is why you cannot find it -- the alignment feature is actually part of tablewidget and more precisely that column of your tablewidget
I looked for alignment in qtablewidget also, and couldn't find anything: https://doc.qt.io/qtforpython/PySide2/QtWidgets/QTableWidget.html
I know set alignment is in a tablewidgetitem, but this isn't considered an item, right?
-
Why not use the Qt.ItemIsUserCheckable flag to get the checkboxes you want rather than widgets San you are doing ?
Widgets set like that will not respond to any role because they are not part of the rendering of the model.
-
Nop, using
setIndexWidgetsetCellWidget puts a widget on that cell but it does not care about the model content.The documentation clearly indicates that it should only be used on special cases for static content and not like done currently to show widgets on each and every line.
-
You didn't (and it was setCellWidget, my bad) but the OP did.
It comes from the original post -
Why not use the Qt.ItemIsUserCheckable flag to get the checkboxes you want rather than widgets San you are doing ?
Widgets set like that will not respond to any role because they are not part of the rendering of the model.
@SGaist said in alignment for QCheckBox in QTableWidget:
Why not use the Qt.ItemIsUserCheckable flag to get the checkboxes you want rather than widgets San you are doing ?
Widgets set like that will not respond to any role because they are not part of the rendering of the model.
I originally went with this and had issues with how I coded it, so I went with the checkbox route. But a clear head does wonders, and I did it this way. Thank you guys.
-
I know this topic is marked solved, but I can't figure out what anyone is saying the solution is. So to be helpful I suggest using setSyleSheet().
For example:
QCheckBox * cb = new QCheckBox("Show");
cb->setStyleSheet("padding-left: 10px;");
tileInfoTable->setCellWidget(TI_SHOW,col,cb);