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. Text across multiple columns in one row like colspan in HTML
Forum Update on Monday, May 27th 2025

Text across multiple columns in one row like colspan in HTML

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.1k 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.
  • W Offline
    W Offline
    WolleKette
    wrote on 5 Aug 2022, 08:46 last edited by
    #1

    Hello at all,
    I use Python and pyside6 and I have a QTreeWidget with some rows (QTreeWidgetItem) and multiple columns. The rows are organized hierarchically by which I mean that there are parent and child nodes.

    Now I want to place a text in the parent nodes which go over several columns. Like colspan in html for example.

    I've been looking around for ages, but haven't found anything. That can not be. Somehow I'm looking in the wrong place. Please give me a tip.

    J 1 Reply Last reply 5 Aug 2022, 09:47
    0
    • W WolleKette
      5 Aug 2022, 08:46

      Hello at all,
      I use Python and pyside6 and I have a QTreeWidget with some rows (QTreeWidgetItem) and multiple columns. The rows are organized hierarchically by which I mean that there are parent and child nodes.

      Now I want to place a text in the parent nodes which go over several columns. Like colspan in html for example.

      I've been looking around for ages, but haven't found anything. That can not be. Somehow I'm looking in the wrong place. Please give me a tip.

      J Offline
      J Offline
      JonB
      wrote on 5 Aug 2022, 09:47 last edited by
      #2

      @WolleKette said in Text across multiple columns in one row like colspan in HTML:

      Now I want to place a text in the parent nodes which go over several columns

      There is QTreeView::setFirstColumnSpanned(). I think that's all for a QTreeView/QTreeWidget. Otherwise have a look at https://stackoverflow.com/questions/27149733/qtreeview-merge-some-cells.

      W 1 Reply Last reply 5 Aug 2022, 16:15
      0
      • J JonB
        5 Aug 2022, 09:47

        @WolleKette said in Text across multiple columns in one row like colspan in HTML:

        Now I want to place a text in the parent nodes which go over several columns

        There is QTreeView::setFirstColumnSpanned(). I think that's all for a QTreeView/QTreeWidget. Otherwise have a look at https://stackoverflow.com/questions/27149733/qtreeview-merge-some-cells.

        W Offline
        W Offline
        WolleKette
        wrote on 5 Aug 2022, 16:15 last edited by
        #3

        @JonB said in Text across multiple columns in one row like colspan in HTML:

        There is QTreeView::setFirstColumnSpanned(). I think that's all for a QTreeView/QTreeWidget.

        I saw the setFirstColumnSpanned Method in the documentation but I have no idea how it should work and I didn’t found examples.

        When I create a new node as follows and insert it in the tree, the text is still limited to the column width.

        ...
        node = QTreeWidgetItem(['Some very long text'])
        node.setFirstColumnSpanned(True)
        tree.addTopLevelItem(node)
        ...
         insert some child nodes
        ...
        tree.expandAll()
        
        1 Reply Last reply
        0
        • W Offline
          W Offline
          WolleKette
          wrote on 5 Aug 2022, 16:23 last edited by
          #4

          @WolleKette said in Text across multiple columns in one row like colspan in HTML:

          Oh, just now I had an idea. The trick is to call setFirstColumnSpanned after adding the node to the tree.
          Then it works.

          1 Reply Last reply
          1

          1/4

          5 Aug 2022, 08:46

          • Login

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