Unsolved Invalid working of QHeaderView::QResizeToContents in QTableWidget
-
Hello. I have got a QTableWidget "_classView" with settings:
_classView->setEditTriggers(QAbstractItemView::NoEditTriggers); _classView->verticalHeader()->setVisible(false); _classView->horizontalHeader()->setVisible(false); _classView->horizontalHeader()->setStretchLastSection(true); _classView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); _classView->setColumnCount(3);
Now, if text in cell is long, it creates a lot of padding on top and bottom of the text which makes the row much larger than it needs to be. Screen:
I would like to achieve similar effect (resizing, without scrollbar), but without unnecessary top and bottom paddings. Anyone knows how I can do it?
-
Hi
Are you sure you trimmed that large value and its not just extra spaces that does it ?
Trying your setup code with a TableView did not produce same result.auto text = R"( { "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": { "GlossEntry": { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": { "para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML"] }, "GlossSee": "markup" } } } } } )"; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); auto _classView = ui->tableView; QStringListModel *model = new QStringListModel(); QStringList list; list << "a" << "b" << "c" << text << "d" << "e" << "long line of text"; model->setStringList(list); _classView->setModel(model); _classView->setEditTriggers(QAbstractItemView::NoEditTriggers); _classView->verticalHeader()->setVisible(false); _classView->horizontalHeader()->setVisible(false); _classView->horizontalHeader()->setStretchLastSection(true); _classView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // _classView->setColumnCount(3); }