[Solved] QTableWidget columns with different width
-
Hi! In my case, every column will contain data with a very specific size. Any clue?
This is my code, but is not working at all:@
StepsViewer::StepsViewer(QWidget *parent) : QTableWidget(parent)
{
setColumnCount(3);
setColumnWidth(0, 80);
setColumnWidth(1, 40);
setColumnWidth(2, 20);
setHorizontalHeaderLabels(QStringList() << tr("Interval") << tr("Frames") << tr("Add"));
...
}@Edit (Andre): fixed code formatting. Please do that yourself next time...
-
I found the problem! All my fault :S
In some place from another class I was doing this:
@
k->stepViewer = new StepsViewer;
k->stepViewer->verticalHeader()->hide();
k->stepViewer->horizontalHeader()->setResizeMode(QHeaderView::Stretch); // <- Aaaargh! :S
@Shame on me! setColumnWidth(int, int) really works!
My apologies :( -
@xtingray here is for making the column widths fit into the qtable widget.
QTableWidget-name.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
Remember to import QHeaderView from PyQt5.Qtwidgets.
Your QTablewidget-name should be replaced by the name you used for it in your code