Results 1 to 7 of 7

Thread: Give a vertical header a title?

  1. #1
    Join Date
    Jun 2014
    Posts
    30
    Thanks
    4
    Qt products
    Qt5

    Default Give a vertical header a title?

    Is there a way to give a vertical header a title? I have attached a screenshot. I am trying to put text in the cell with the blue question mark in it.

    Capture.PNG

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Give a vertical header a title?

    Quote Originally Posted by jmalicke View Post
    Is there a way to give a vertical header a title? I have attached a screenshot. I am trying to put text in the cell with the blue question mark in it.
    Unless I am misunderstanding your question, you give the column a title the same way you did for the other columns "State Variable" and "Volitalization Option".

    How did you set the other column headings? Can you provide more about what classes you're using? i.e. QTableView, QTableWidget, etc?

  3. #3
    Join Date
    Jun 2014
    Posts
    30
    Thanks
    4
    Qt products
    Qt5

    Default Re: Give a vertical header a title?

    I am inheriting from QTableView. Here is headerData which is responsible for the columns:

    Qt Code:
    1. if (orientation == Qt::Horizontal) {
    2. switch (section)
    3. {
    4. case COL_STATE_VARIABLE:
    5. return tr("State variable");
    6. case COL_VOLATILIZATION_OPTION:
    7. return tr("Volatilization option");
    8. ...
    9. else
    10. {
    11. SystemData & system = systemDataCopy[section];
    12. return system.getDescription().c_str();
    13. }
    To copy to clipboard, switch view to plain text mode 

    As far as I know, the column I am trying to label is not a proper table column but is instead a header itself (a vertical header). I am basically trying to give a horizontal header to my vertical headers.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Give a vertical header a title?

    You can place a widget in that corner of the view using QAbstractScrollArea::setCornerWidget(). Make that widget a QLabel and you can place whatever text or image you would like. There is no way for this to be provided by a standard item model.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Give a vertical header a title?

    Quote Originally Posted by ChrisW67 View Post
    You can place a widget in that corner of the view using QAbstractScrollArea::setCornerWidget().
    Doesn't this place the widget between scrollbars (i.e. bottom-right corner of the widget)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Give a vertical header a title?

    Oh yes, sorry, my bad %-) There is a property to enable the top-left button but I cannot see an easy way to set text there.

    See: http://www.qtcentre.org/threads/6252...3027#post33027 for a QTableWidget example. You will need to verify that it still works/matches given that it pokes around private internals.

  7. #7
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Give a vertical header a title?

    I am able to have text show up in the spot left of the horizontal header and above the vertical header in a QTableView by doing the following.

    During your gui initialization:

    Qt Code:
    1. tableview->setCornerWidgetEnabled(true);
    2. tableview->setCornerWidgetVisible(true);
    3. m_btn = tableview->findchild<QAbstractButton*>(); // m_btn is QAbstractButton* member variable
    4. if (m_btn)
    5. {
    6. m_btn->setText("Hdr");
    7. m_btn->installEventFilter(this);
    8. m_btn->setEnabled(true);
    9. m_btn->setVisible(true);
    10. }
    To copy to clipboard, switch view to plain text mode 

    The event filter you installed earlier to paint the corner button:

    Qt Code:
    1. MainWindow::eventFilter(QObject *object, QEvent *event)
    2. {
    3. if (event->type() == QEvent::Paint && object == m_btn)
    4. {
    5. opt.init(m_btn);
    6. QStyle::State state = QStyle::State_None;
    7. if (m_btn->isEnabled())
    8. state |= QStyle::Style_Enabled;
    9. if (m_btn->isDown())
    10. state |= QStyle::Style_Sunken;
    11. if (m_btn->isActiveWindow())
    12. state |= QStyle::Style_Active;
    13. opt.state = state;
    14. opt.rect = m_btn->rect();
    15. opt.text = m_btn->text();
    16. opt.position = QStyleOptionHeader::OnlyOneSection;
    17. QStylePainter painter(m_btn);
    18. painter.drawControl(QStyle::CE_Header, opt);
    19. return true;
    20. }
    21.  
    22. return QMainWindow::eventFilter(object, event);
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 

    I don't know how to control the vertical header's width, so if the text you're drawing is wider than the vertical header, it will clip. Hopefully this will get you started.

    Regards,

    Jeff

Similar Threads

  1. Cannot hide QTableWidget's vertical header.
    By adutzu89 in forum Newbie
    Replies: 2
    Last Post: 25th January 2014, 11:12
  2. Twisted Letters in Vertical Axis Title
    By DrunkenUFOPilot in forum Qwt
    Replies: 6
    Last Post: 24th January 2012, 23:56
  3. Change tableView vertical header
    By tinysoft in forum Newbie
    Replies: 1
    Last Post: 17th September 2011, 08:35
  4. Vertical Header For QTreeView
    By wirasto in forum Qt-based Software
    Replies: 1
    Last Post: 12th October 2010, 05:53
  5. No Sort Vertical Header
    By wirasto in forum Qt Programming
    Replies: 4
    Last Post: 1st July 2009, 10:54

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.