Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PySide2.QtWidgets.QTableWidget: why it's impossible to set column width less than 35 and row height less than 21?
Forum Updated to NodeBB v4.3 + New Features

PySide2.QtWidgets.QTableWidget: why it's impossible to set column width less than 35 and row height less than 21?

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 3 Posters 880 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zunder
    wrote on last edited by Zunder
    #1

    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
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What are you going to show in these little squares ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Z 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        What are you going to show in these little squares ?

        Z Offline
        Z Offline
        Zunder
        wrote on last edited by Zunder
        #3

        @SGaist , Hi! And thank you!
        I want to print single digits (from 1 to 6) there.
        Frankly speaking, I want to visualize the process of solving one kata from codewars.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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).

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Z 1 Reply Last reply
          0
          • SGaistS SGaist

            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).

            Z Offline
            Z Offline
            Zunder
            wrote on last edited by Zunder
            #5

            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:
            993ecb3d-3c85-4573-b565-4febaf119523-image.png

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I wonder if the Pixelator example would be a good starting point for you.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved