Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QTableView question
Qt 6.11 is out! See what's new in the release blog

QTableView question

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 5 Posters 4.0k 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.
  • T Offline
    T Offline
    theomarzz.nl
    wrote on last edited by
    #1

    Hello All,

    I've got a simple question.
    I have QTableView which is attached to custom model and custom delegate.
    The tableview shows me 3 rows. But the columns don't fill up the entire width of the tableview.
    How can i make it so that 1 particular column sizes so that all columns will fill the width of the table view.
    I looked in the documentation but I can't find it. I think i missed it.

    Regards,

    Theo

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      Try this:

      @myTableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);@

      --
      Vasiliy

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtrahul
        wrote on last edited by
        #3

        Look this : http://doc.qt.nokia.com/stable/qtableview.html

        1 Reply Last reply
        0
        • I Offline
          I Offline
          Immii
          wrote on last edited by
          #4

          [quote author="qtrahul" date="1293382585"]Look this : http://doc.qt.nokia.com/stable/qtableview.html[/quote]

          Please put the link in the format use "link":http://doc.qt.nokia.com/stable/qtableview.html icon located above your "Post Reply" box

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Alternatively you can call

            @
            tableView->horizontalHeader()->setStretchLastSection(true);
            @

            It sets up a different behaviour in than resizeMode. See QHeaderViews docs on "strechLastSection property":http://doc.qt.nokia.com/stable/qheaderview.html#stretchLastSection-prop for a detailed description.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • T Offline
              T Offline
              theomarzz.nl
              wrote on last edited by
              #6

              Thank you all,

              But setResizeMode(QHeaderView::Stretch) will stretch the columns evenly in the tablefield & setStretchLastSection(true) will do it only for the last column.
              In my case I want the middle column to stretch only. But when a user adds a column to the tableview to see more detail I still want to stretch that same column (the one that was the middle column).
              After some digging I found the sizeHint method in the QStyledItemDelegate and I am still figuring out how to use it.
              Also promising is QTableView::resizeColumnToContents ( int column ). Somehow I have to tie (signal & slot) the slot to the delegate or model to resize the right column every time.

              Regards,

              Theo

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                This cannot be achieved out of the box. The sizeHint approach might not work as expected, because it's only a hint, not a constraint.

                You could could create your own QHeaderView subclass and add the functionality there. You can add it to the table view with setHorizontalHeader().

                http://www.catb.org/~esr/faqs/smart-questions.html

                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