The Ultimate Qt Community site
Home News Forum Wiki Contest FAQ Links

Go Back   Qt Centre Forum > Qt > Qt Programming

Qt Programming General Qt programming issues.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 26th March 2007, 03:46
McKee McKee is offline
Novice
 
Join Date: Oct 2006
Location: Massachusetts, USA
Qt products used: Qt4
Qt platforms used: Windows
Posts: 19
Thanks: 5
Thanked 0 Times in 0 Posts
Question QTableWidget NW corner header item?

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

Qt Code:
1
QTableWidget::setHorizontalHeaderLabels ( const QStringList & labels )
and
Qt Code:
1
QTableWidget::setVerticalHeaderLabels ( const QStringList & labels )
but they don't seem to provide access to the item at the corner. Nor do

Qt Code:
1
QTableWidgetItem * QTableWidget::horizontalHeaderItem ( int column ) const
and
Qt Code:
1
QTableWidgetItem * QTableWidget::verticalHeaderItem ( int row) const
Perhaps accessing a header itself via

Qt Code:
1
QHeaderView * QTableView::horizontalHeader () const
or
Qt Code:
1
QHeaderView * QTableView::verticalHeader () const
but then what to do with it?

thanks!
Reply With Quote
  #2  
Old 27th March 2007, 09:19
jpn jpn is offline
Guru
 
Join Date: Feb 2006
Location: Tampere, Finland
Qt products used: Qt4
Qt platforms used: Unix/X11 , Windows
Posts: 6,128
Thanks: 36
Thanked 1,378 Times in 1,318 Posts
Default Re: QTableWidget NW corner header item?

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).
__________________
J-P Nurmi
Reply With Quote
  #3  
Old 30th March 2007, 02:18
McKee McKee is offline
Novice
 
Join Date: Oct 2006
Location: Massachusetts, USA
Qt products used: Qt4
Qt platforms used: Windows
Posts: 19
Thanks: 5
Thanked 0 Times in 0 Posts
Default Re: QTableWidget NW corner header item?

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.
Reply With Quote
  #4  
Old 30th March 2007, 06:56
jpn jpn is offline
Guru
 
Join Date: Feb 2006
Location: Tampere, Finland
Qt products used: Qt4
Qt platforms used: Unix/X11 , Windows
Posts: 6,128
Thanks: 36
Thanked 1,378 Times in 1,318 Posts
Default Re: QTableWidget NW corner header item?

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.
Attached Files
File Type: cpp main.cpp (1.7 KB, 52 views)
__________________
J-P Nurmi
Reply With Quote
The following user says thank you to jpn for this useful post:
McKee (30th March 2007)
  #5  
Old 30th March 2007, 14:30
McKee McKee is offline
Novice
 
Join Date: Oct 2006
Location: Massachusetts, USA
Qt products used: Qt4
Qt platforms used: Windows
Posts: 19
Thanks: 5
Thanked 0 Times in 0 Posts
Default Re: QTableWidget NW corner header item?

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
Reply With Quote
  #6  
Old 23rd July 2007, 03:22
jtaylor108 jtaylor108 is offline
Beginner
 
Join Date: Jul 2007
Qt products used: Qt4
Qt platforms used: Windows
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Default Re: QTableWidget NW corner header item?

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:

Qt Code:
1
2
3
4
5
6
7
8
9
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
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
QListView header move on drag and Expandability to get applied to column 0 only vinnu Qt Programming 0 10th November 2006 13:46
QTableWidget, header behavior hyling Qt Programming 1 14th October 2006 08:03
QTableWidget item checkable and combo? darpan Qt Programming 1 10th October 2006 07:12
How to delete header on QTableWidget jlbrd Qt Programming 2 18th July 2006 21:00
QTableView header in corner danstr Qt Programming 3 18th May 2006 20:16


All times are GMT +1. The time now is 00:52.


Powered by vBulletin Version 3.7.4 Copyright ©2000 - 2009, Jelsoft Enterprises Ltd., vRewrite 1.5 SEOed URLs completed by Tech Help Forum and Chalo Na.
© 2006–2009 Qt Centre - The Ultimate Qt Community site
Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.