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 stretch table column only once, on loading

How to stretch table column only once, on loading

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.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.
  • Y Offline
    Y Offline
    yura-vel
    wrote on last edited by
    #1

    I have custom class inherited from QTableView that shows custom model.
    For example view shows three columns A, B, C, D. Each of which has own initial size, that was setup by

    @ setColumnWidth() @

    I need to stretch column B as more as possible when view is displayed to user. After that user should have ability to change width of any column.

    If to use

    @horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch )@

    column will be stretched but after this user can't to change it width.

    How to solve this problem?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      When instantiating/ showing the view, run this code (after the data is loaded!):
      @
      horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
      horizontalHeader()->setSectionResizeMode(1, QHeaderView::Interactive);
      @

      If that does not work good, then read the section size after Streatch, set to Interactive, then set the saved size on that column.

      Byt the way, when you set Stretch on a column, it will occupy as much of the space as possible, but you can still change size of other columns and that setting will affect the stretched column, too.

      Another option is to use cascading section resizes.

      (Z(:^

      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