Is it possible to get the width of a vertical header section in a QTableView?
-
wrote on 24 Feb 2022, 15:21 last edited by
Hey guys, I can't find a way to get the width of a vertical header section in a QTableView with both vertical and horizontal headers.
I have read the documentation and the only things I found areint QHeaderView::sectionSize(int logicalIndex) const
which returns only the height of the section (for vertical headers) andint QHeaderView::length() const
which returns the length along the orientation of the header (after a few tests I've found that this is greather than the section width and I don't know why).
Any help would be highly appreciated!! -
To get the row of a height you can use QTableView::rowHeight(int), to get the widget use QTableView::columnWidth(int)
-
To get the row of a height you can use QTableView::rowHeight(int), to get the widget use QTableView::columnWidth(int)
wrote on 24 Feb 2022, 15:48 last edited by user13@Christian-Ehrlicher said in Is it possible to get the width of a vertical header section in a QTableView?:
To get the row of a height you can use QTableView::rowHeight(int), to get the widget use QTableView::columnWidth(int)
Thank you for the reply!
Is there any similar method in QHeaderView?
What I'm trying to do is to place a QLineEdit over a double clicked header section so I defined a QHeaderView subclass and whenever a section (both horizontal or vertical) is double clicked a QLineEdit appears on top of that section.
I was inspired by this post.What i have is something like this:
void CustomHeader::onSectionDoubleClicked(int section) { qDebug() << length(); qDebug() << height(); sectionDoubleClicked = section; lineEdit = new QLineEdit(this); //color changed just for testing QPalette *palette = new QPalette(); palette->setColor(QPalette::Base,Qt::gray); lineEdit->setPalette(*palette); if(orientation() == Qt::Horizontal) lineEdit->setGeometry(sectionViewportPosition(section), 0, sectionSize(section), height()); else if(orientation() == Qt::Vertical) lineEdit->setGeometry(0, sectionViewportPosition(section), length(), sectionSize(section)); lineEdit->show(); lineEdit->setFocus(); connect(lineEdit, SIGNAL(editingFinished()), this, SLOT(onEditingFinished())); }
In the case
orientation() == Qt::vertical
the QLineEdit which shows up is larger than the section becauselenght()
is greather than the section width. -
QHeaderView is a QWidget, so it has QWidget::size()
-
QHeaderView is a QWidget, so it has QWidget::size()
wrote on 24 Feb 2022, 15:59 last edited by@Christian-Ehrlicher said in Is it possible to get the width of a vertical header section in a QTableView?:
QHeaderView is a QWidget, so it has QWidget::size()
Thank you so much! With
size().width()
everything works fine!
1/5