0
votes

The column width 'I' in my table is too large. I tried with

self.table.setColumnWidth(1,8) # and also lower values
# or:
self.table.resizeColumnToContents(1)

but the minimum width I get is the one you see in the image:

enter image description here

This is the whole code:

    self.table = QTableWidget(2,3,self)
    self.table.setHorizontalHeaderLabels(["Name","I","City"])
    self.table.setItem(0,0,QTableWidgetItem("Mark"))
    self.table.setItem(0,1,QTableWidgetItem("P"))
    self.table.setItem(0,2,QTableWidgetItem("London"))
    self.table.setItem(1,0,QTableWidgetItem("John"))
    self.table.setItem(1,1,QTableWidgetItem("M"))
    self.table.setItem(1,2,QTableWidgetItem("liverpool"))
    self.table.setColumnWidth(1,8)
    #self.table.resizeColumnToContents(1)
    self.table.setStyleSheet("QTableWidget{background-color:white;color:blue;font-size:11pt}QTableWidget::item{padding-left:0px;padding-right:0px}")
1

1 Answers

0
votes

For example) How to fit the size of the last column to the table width

ui->QTableWidget->horizontalHeader()->setStretchLastSection(true);

size of the last column can change as Table width.

You can also change the Row

ui->QTableWidget->resizeRowToContents();