Set height of row of table
-
Thanks @SGaist, actually in my opinion, you mixed the horizontal header with verical header already. I thinks this line makes the last column (not the row) to stretch to fit the width of the table. If I remove this line, the new table will look like this.
I am so confused because never ever had this problem :(. I still don't think there is problem with my code, because it works well with QtCreator, but in VS problem appears.
-
Argle… Even after all these years I manage to get this one wrong…
One thing that I haven't seen in your code, where do you set the row count in your widget ?
-
Can you provide a minimal compilable example that reproduces that ?
-
@SGaist : I tested right on my code. If i add the line with RowCount in, in Qt Designer I dont set 1 row any more, the result still does not change. I still receive the table above.
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); ui->tableWidget->setRowCount(1); ui->tableWidget->setColumnCount(5); ui->tableWidget->setHorizontalHeaderLabels(QStringList() << tr("First") << tr("Second") << tr("Third") << tr("Fourth") << tr("Fifth"));
-
Which OS are you running ?
Testing with:
QApplication app(argc, argv); QTableWidget tableWidget; tableWidget.setSelectionBehavior(QAbstractItemView::SelectRows); tableWidget.setSelectionMode(QAbstractItemView::SingleSelection); tableWidget.setRowCount(1); tableWidget.setColumnCount(5); tableWidget.setHorizontalHeaderLabels(QStringList() << QObject::tr("First") << QObject::tr("Second") << QObject::tr("Third") << QObject::tr("Fourth") << QObject::tr("Fifth")); tableWidget.show(); return app.exec();
shows the table widget as you want it.
-
@SGaist : I am using Windows 8.1, Visual Studio 2013, add-in Qt 5.5.1. If you use this code with just Qt Creator, it works. But i am coding with VS, the result is not good. If you can test it, please test with VS and shows me if you have the same result.
-
Sorry, I don't have that OS nor that version of Visual Studio at hand.
But I find it pretty surprising that the exact same code yields different result using the same compiler with only the IDE changing.
-
QTableWidget already has an internal model otherwise it's a QTableView.