PySide2.QtWidgets.QTableWidget: why it's impossible to set column width less than 35 and row height less than 21?
-
I am using code like following, trying to create a table of square cells. But when I try to use 5 (or even10) as cell size, I get table with rectangular cells with size of 35x21?
def create_square_table(self, cell_size=5, cell_number=5): square_table = QtWidgets.QTableWidget() square_table.verticalHeader().setDefaultSectionSize(cell_size) square_table.horizontalHeader().setDefaultSectionSize(cell_size) square_table.setColumnCount(cell_number) square_table.setRowCount(cell_number) square_table.horizontalHeader().hide() square_table.verticalHeader().hide() square_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) square_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) square_table.setAlternatingRowColors(True) square_table.setEnabled(False) print('Column width:', square_table.columnWidth(0)) print('Row height:', square_table.rowHeight(0)) return square_table table = self.create_square_table()
The text printed in console is:
Column width: 35 Row height: 21
-
Hi and welcome to devnet,
What are you going to show in these little squares ?
-
And how many do you want to show in total ?
I have the feeling that you might not be using the right tool (I may be wrong though).
-
I want to show 6 by 6 tables, that will be CellWidgets of an outer table of 6 by 6. So small square cells are better for this task, because the whole table can be square and smaller than table that is made of rectanguler cells 35x21.
I was thinking about using gridLayot instead of tableWidgets. But in my opinion it will be more difficult to manage such an interface. Am I right?
This is how my intermediate result with 35x21 inner cells looks like:
-
I wonder if the Pixelator example would be a good starting point for you.