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 set width of one column int a QTableView?
QtWS25 Last Chance

How to set width of one column int a QTableView?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 6.4k 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.
  • qazaq408Q Offline
    qazaq408Q Offline
    qazaq408
    wrote on last edited by
    #1

    Now there's a QTableView with 5 columns.The programme will run on different kinds of computers(defferent size of screen),so I hpoe QTableView will has different width when the programme is running.
    The second column of QTableView is a QPushButton that's put on by QStyledItemDelegate.I hope the second column of TableView has fix size,other columns can automtaic change size when the programme run different screen.
    Then,I do like this:

    myTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    myTable->setColumnWidth(1,50);
    

    But It doesn't work,I find in Asistant,the document tell me the fun doesn't work if I use setSectionResizeMode() brfore.
    I hope the width of second column is fixed and other columns is stretch.How to achieve it?

    jsulmJ 1 Reply Last reply
    0
    • qazaq408Q qazaq408

      Now there's a QTableView with 5 columns.The programme will run on different kinds of computers(defferent size of screen),so I hpoe QTableView will has different width when the programme is running.
      The second column of QTableView is a QPushButton that's put on by QStyledItemDelegate.I hope the second column of TableView has fix size,other columns can automtaic change size when the programme run different screen.
      Then,I do like this:

      myTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
      myTable->setColumnWidth(1,50);
      

      But It doesn't work,I find in Asistant,the document tell me the fun doesn't work if I use setSectionResizeMode() brfore.
      I hope the width of second column is fixed and other columns is stretch.How to achieve it?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @qazaq408 What about this one: https://doc.qt.io/qt-5.11/qheaderview.html#setSectionResizeMode-1

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • qazaq408Q Offline
        qazaq408Q Offline
        qazaq408
        wrote on last edited by
        #3

        Thank you....
        I read document not careful enough ,My mistake.....

        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