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. QTableWidget expanding
Qt 6.11 is out! See what's new in the release blog

QTableWidget expanding

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 904 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.
  • N Offline
    N Offline
    nammidd
    wrote on last edited by nammidd
    #1

    The question seems simple, but for some reason I can’t find a solution. How to make my QTableWidget not to expand itself beyond the existing columns and rows?

    	QTableWidget* table_widget = new QTableWidget(6, 3);
    	table_widget->setColumnWidth(0, 150);
    	table_widget->setColumnWidth(1, 50);
    	table_widget->setColumnWidth(2, 50);
    	
    	QHeaderView* vertical_header = table_widget->verticalHeader();
    	vertical_header->setSectionResizeMode(QHeaderView::Fixed);
    
    	QHeaderView* horizontal_header = table_widget->horizontalHeader();
    	horizontal_header->setSectionResizeMode(QHeaderView::Fixed);
    

    picture

    JonBJ 1 Reply Last reply
    0
    • N nammidd

      The question seems simple, but for some reason I can’t find a solution. How to make my QTableWidget not to expand itself beyond the existing columns and rows?

      	QTableWidget* table_widget = new QTableWidget(6, 3);
      	table_widget->setColumnWidth(0, 150);
      	table_widget->setColumnWidth(1, 50);
      	table_widget->setColumnWidth(2, 50);
      	
      	QHeaderView* vertical_header = table_widget->verticalHeader();
      	vertical_header->setSectionResizeMode(QHeaderView::Fixed);
      
      	QHeaderView* horizontal_header = table_widget->horizontalHeader();
      	horizontal_header->setSectionResizeMode(QHeaderView::Fixed);
      

      picture

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @nammidd
      This is not to do with the columns/rows content, but to do with QTableWidget itself and what layout it is in. You have to start by telling us: in that picture, is it in layout and what are the layout settings? Or I think you can try table_widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed), I get confused too about widget size policy vs layout! :(

      N 1 Reply Last reply
      0
      • JonBJ JonB

        @nammidd
        This is not to do with the columns/rows content, but to do with QTableWidget itself and what layout it is in. You have to start by telling us: in that picture, is it in layout and what are the layout settings? Or I think you can try table_widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed), I get confused too about widget size policy vs layout! :(

        N Offline
        N Offline
        nammidd
        wrote on last edited by nammidd
        #3

        @JonB said in QTableWidget expanding:
        it is in QHBoxLayout, wihout any settings.

        you can try table_widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)

        I tried it , scrollbars appears then https://imgur.com/a/6FmrKI2

        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