+ Reply to Thread
Results 1 to 6 of 6

Thread: QTableWidget NW corner header item?

  1. Join Date
    Oct 2006
    Location
    Massachusetts, USA
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    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 )
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. QTableWidget::setVerticalHeaderLabels ( const QStringList & labels )
    To copy to clipboard, switch view to plain text mode 

    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
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. QTableWidgetItem * QTableWidget::verticalHeaderItem ( int row) const
    To copy to clipboard, switch view to plain text mode 

    Perhaps accessing a header itself via

    Qt Code:
    1. QHeaderView * QTableView::horizontalHeader () const
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. QHeaderView * QTableView::verticalHeader () const
    To copy to clipboard, switch view to plain text mode 

    but then what to do with it?

    thanks!

  2. Join Date
    Feb 2006
    Location
    Tampere, Finland
    Posts
    6,251
    Thanks
    36
    Thanked 1,422 Times in 1,354 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    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

  3. Join Date
    Oct 2006
    Location
    Massachusetts, USA
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    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.

  4. Join Date
    Feb 2006
    Location
    Tampere, Finland
    Posts
    6,251
    Thanks
    36
    Thanked 1,422 Times in 1,354 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    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
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    McKee (30th March 2007)

  6. Join Date
    Oct 2006
    Location
    Massachusetts, USA
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    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

  7. Join Date
    Jul 2007
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    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. CTableWidget::CTableWidget( QWidget* parent ):
    2. QTableWidget( parent )
    3. {
    4. QList< QAbstractButton* > buttons = qFindChildren< QAbstractButton* >( this );
    5. for ( int i=0; i<buttons.size(); ++i )
    6. {
    7. buttons[i]->setStyleSheet( "QWidget{ background-color:red; }" );
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    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 to Thread

Similar Threads

  1. Replies: 0
    Last Post: 10th November 2006, 14:46
  2. QTableWidget, header behavior
    By hyling in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2006, 08:03
  3. QTableWidget item checkable and combo?
    By darpan in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2006, 07:12
  4. How to delete header on QTableWidget
    By jlbrd in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2006, 21:00
  5. QTableView header in corner
    By danstr in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2006, 20:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts