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.
Attachment 10803
Printable View
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.
Attachment 10803
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?
I am inheriting from QTableView. Here is headerData which is responsible for the columns:
Code:
if (orientation == Qt::Horizontal) { switch (section) { case COL_STATE_VARIABLE: return tr("State variable"); case COL_VOLATILIZATION_OPTION: return tr("Volatilization option"); ... else { SystemData & system = systemDataCopy[section]; return system.getDescription().c_str(); }
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.
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.
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.
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:
Code:
tableview->setCornerWidgetEnabled(true); tableview->setCornerWidgetVisible(true); m_btn = tableview->findchild<QAbstractButton*>(); // m_btn is QAbstractButton* member variable if (m_btn) { m_btn->setText("Hdr"); m_btn->installEventFilter(this); m_btn->setEnabled(true); m_btn->setVisible(true); }
The event filter you installed earlier to paint the corner button:
Code:
{ { QStyleOptionHeader opt; opt.init(m_btn); if (m_btn->isEnabled()) if (m_btn->isDown()) if (m_btn->isActiveWindow()) opt.state = state; opt.rect = m_btn->rect(); opt.text = m_btn->text(); return true; } }
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