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 can i make the column width enough fit for the content in QTreeWidget?

how can i make the column width enough fit for the content in QTreeWidget?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.0k 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.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    how can i make the column width enough fit for the content in QTreeWidget?

    1 Reply Last reply
    1
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      void QTreeView::resizeColumnToContents(int column)

      It's a slot, so when you add data, call it and it will do it for you ;-)

      Greetz, Jeroen

      RokeJulianLockhartR 1 Reply Last reply
      1
      • JeroentjehomeJ Jeroentjehome

        void QTreeView::resizeColumnToContents(int column)

        It's a slot, so when you add data, call it and it will do it for you ;-)

        RokeJulianLockhartR Offline
        RokeJulianLockhartR Offline
        RokeJulianLockhart
        wrote on last edited by
        #3
        QTreeView::resizeColumnToContents(int column)
        

        If of interest to anyone in the future, iterating over the columns and applying this is quite trivial:

        #!/usr/bin/env python3.13
        import \
            builtins, \
            PyQt6.QtWidgets
        
        self.tree_widget = PyQt6.QtWidgets.QTreeWidget()
        tree_widget_header_labels: builtins.list = ["Name", "Location"]
        self.tree_widget.setHeaderLabels(tree_widget_header_labels)
        
        # Iteration:
        for i in builtins.range(builtins.len(tree_widget_header_labels)):
            self.tree_widget.resizeColumnToContents(i)
        

        When using a forum, remember to tag the person you are responding to, in case they are not subscribed to the thread.

        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