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. QTableWidget setColumnWidth didn't work in Qt6, but work in Qt5
Forum Updated to NodeBB v4.3 + New Features

QTableWidget setColumnWidth didn't work in Qt6, but work in Qt5

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 416 Views 2 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.
  • K Offline
    K Offline
    Knightly
    wrote on last edited by
    #1

    In Qt6(6.6.1), if I use setStyleSheet, the setColumnWidth didn't work. but in Qt5(5.11.2), it works well.

    here is the code.
    setColumnCount(2)
    setStyleSheet("QTableView { border:none; background:transparent;}")
    setColumnWidth(0, 30)
    setColumnWidth(0, 60)

    I try to use ResizeMode.ResizeToContents, ResizeMode.Fixed, they didn't work.
    So is it an issue or is there a way to set the column width in QSS?
    qt6-issue.PNG

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

      Hi and welcome to devnet,

      Which OS are you on ?

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

      K 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Which OS are you on ?

        K Offline
        K Offline
        Knightly
        wrote on last edited by
        #3

        @SGaist hi, we use Windows 10

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          Which OS are you on ?

          K Offline
          K Offline
          Knightly
          wrote on last edited by
          #4

          @SGaist and I use setCellWidget to add widget, the widget is a QLabel.

          labelWidget.setFixedWidth(30)
          setCellWidget(0,0, labelWidget)

          1 Reply Last reply
          1
          • K Offline
            K Offline
            Knightly
            wrote on last edited by
            #5

            use setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents), and remove setColumnWidth, it works(not perfect).
            but I still don't know why ResizeMode.Fixed, and setColumnWidth(0, 30) didn't work.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Upgrade to a more recent version: https://bugreports.qt.io/browse/QTBUG-122109

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              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