QTableWidget top-left corner properties
-
Hi,
I'm just curious if it's possible to access and set properties to the top-left cell of a QTableWidget when the horizontal and vertical headers are visible.
If there is a chance, I would like to set a little text in that cell. All I could find about it was the "cornerWidget()":http://qt-project.org/doc/qt-5/qabstractscrollarea.html#cornerWidget method of the QTableView class but I am not sure if I am following the right clue.
Any help is very welcome! :)
-
-It's not a cell. It's actually outside of the table and yes, that's the corner widget.-
Sorry. That's not right. That's actually a fragment between scroll bars.This cell is actually a button that selects all cells. There's no method exposed to get to it but if you call on the table children<QPushButton> or children<QToolButton> or something like this you might be able to get a pointer to it and change its text.
-
Hi,
I don't want to ruin the thing, but if you are thinking about the "select all cells" corner button, then it's an internal widget called QTableCornerButton that you can't modify from the outside at least officially
-
What he said :P
-
Well, my requirement is to set a text right there for usability/information reasons only. No interaction is needed, no buttons, no actions.
But as far as you said, it seems impossible for now :/
-
Don't give up so easily ;)
There's an easy way to do it with a few more lines of code:
label = new QLabel("Txt!", tableWidget); label->setAlignment(Qt::AlignCenter); label->setAttribute(Qt::WA_TransparentForMouseEvents); connect(tableWidget->verticalHeader(), &QHeaderView::geometriesChanged, whatever, &Whatever::resizeCorner); connect(ui->tableWidget->horizontalHeader(), &QHeaderView::geometriesChanged, whatever, &Whatever::resizeCorner); //slot in Whatever class void Whatever::resizeCorner() { label->setGeometry(0, 0, tableWidget->verticalHeader()->width(), tableWidget->horizontalHeader()->height()); }
This doesn't use any hacks or internal Qt stuff so it's a pretty clean solution.