Important: Please read the Qt Code of Conduct -

QTableWidget expanding

  • 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();
    	QHeaderView* horizontal_header = table_widget->horizontalHeader();


  • @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! :(

  • @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

Log in to reply