View Full Version : QTableWidget NW corner header item?
McKee
26th March 2007, 04:46
Embarassing to ask, but how would I access the top left corner header item in a QTableWidget that has both a horizontal and a vertical header? This is the header item they have in common. I can use
QTableWidget::setHorizontalHeaderLabels ( const QStringList & labels )
and
QTableWidget::setVerticalHeaderLabels ( const QStringList & labels )
but they don't seem to provide access to the item at the corner. Nor do
QTableWidgetItem * QTableWidget::horizontalHeaderItem ( int column ) const
and
QTableWidgetItem * QTableWidget::verticalHeaderItem ( int row) const
Perhaps accessing a header itself via
QHeaderView * QTableView::horizontalHeader () const
or
QHeaderView * QTableView::verticalHeader () const
but then what to do with it?
thanks!
jpn
27th March 2007, 10:19
What would you like to do with it? It's not a header item actually but a button (for more information, see QTableCornerButton at the beginning of src/gui/itemviews/qtableview.cpp).
McKee
30th March 2007, 03:18
I'd like to set its text; that's all.
I see the code you pointed me to -- thanks. QTableView's private cornerWidget member is the QTableCornerButton, and it oddly hides another member of the same name down the inheritance chain, namely QAbstractScrollArea::cornerWidget. Only the latter is exposed via the method cornerWidget(). Doh. QTableWidget::cornerWidget() returns not the QTableCornerButton instance, but QAbstractScrollArea::cornerWidget, which is understandably NULL. Wish there was a QTableView::cornerButton() method.
jpn
30th March 2007, 07:56
It's still possible with some rather ugly "hacking". One would need to use for example QObject::findChild() to get access to the private corner button. An event filter is required for "overriding" the button's paintEvent() (QTableCornerButton::paintEvent() doesn't paint the text even if the button had text set). I have attached an example.
This is, of course, not recommended way for doing it. It is a private button and may be a subject to change in the future. I suggest sending a suggestion about the issue to the Task-Tracker (http://www.trolltech.com/developer/task-tracker).
McKee
30th March 2007, 15:30
Wow! Nice work. Thanks for the example code.
Another way to solve the problem is to just create a new leftmost column, for which I can set the text of the top header item. I was hoping to avoid that because my table works better with my leftmost data in the vertical header items. But it's do-able.
I'll look into the TaskTracker suggestion.
McKee
jtaylor108
23rd July 2007, 04:22
Does anyone know if there is there any way to format the NW corner button using a stylesheet? Setting the following style sheet on the NW corner button in my CTableWidget constructor doesn't seem to do anything:
CTableWidget::CTableWidget( QWidget* parent ):
QTableWidget( parent )
{
QList< QAbstractButton* > buttons = qFindChildren< QAbstractButton* >( this );
for ( int i=0; i<buttons.size(); ++i )
{
buttons[i]->setStyleSheet( "QWidget{ background-color:red; }" );
}
}
I can paint the button myself using an event filter, but it doesn't seem like an end user can modify the appearance.
TIA,
jt
vBulletin® v3.7.1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.