Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set ResizetoContent for a single column in TableWidget?
QtWS25 Last Chance

How to set ResizetoContent for a single column in TableWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.8k Views
  • 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.
  • S Offline
    S Offline
    sysla1
    wrote on last edited by sysla1
    #1

    Hello,

    I am new to Qt and I am using PyQt 5.8.

    I had my columns set to resizeColumnsToContents() but when setting setStretchLastSection(True), the table is always resizing to fit the content, even though I am manually setting the setStretchLastSection(True) once more.

    Is there anything I can do to prevent it from doing so? I thought about setting 6 of my 7 columns to resizetoContent, so the StretchLastSection won't be overwritten, but I can't seem to find a way to do so.

    (setStretchLastSection(True) is also set to true through Qt-Designer)

    my table is called table_1. my current code is below:

            self.table_1.resizeRowsToContents()
            self.table_1.resizeColumnsToContents()
            self.table_1.verticalHeader().setStretchLastSection(True)
    

    thanks, I am open for constructive critics.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      What Qt version are you using?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sysla1
        wrote on last edited by
        #3

        Oups, Qt 5.8

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          http://doc.qt.io/qt-5/qheaderview.html#setSectionResizeMode-1 lets you set the resize mode for each column

          P.S.

          my columns set to resizeColumnsToContents() but when setting setStretchLastSection(True)

          self.table_1.verticalHeader().setStretchLastSection(True)

          verticalHeader is for the rows, horizontalHeader is for the columns

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1

          • Login

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