PDA

View Full Version : few questions related to QTreeWidget



prakash
24th February 2006, 11:21
Dear All

I have been posting to qtforum for few information on QTreeWidget but didn't find suitable solution. Please help me on the following -

1) How to set row height for QTreeWidget as in QTreeView

2) How to show(or paint) grid for QTreeWidget as in QTreeView

3)How to override default alternating row color for QTreeWidget

and

4) I need to show status in the right corner of the Toolbar. So, please suggest how to place multiple vertically stacked Qlable in that place.

Thanks.:confused: ;)

jacek
24th February 2006, 12:53
1) How to set row height for QTreeWidget as in QTreeView
2) How to show(or paint) grid for QTreeWidget as in QTreeView
QTreeWidget is a QTreeView, so you should be able to do it the same way.


3)How to override default alternating row color for QTreeWidget
Get the QPalette object using palette() method, change QPalette::AlternateBase colour and then set the modified palette using setPalette().


4) I need to show status in the right corner of the Toolbar. So, please suggest how to place multiple vertically stacked Qlable in that place.
Tool bar? Or did you mean status bar?

prakash
26th February 2006, 05:51
Yes in the Toolbar. I have 5 buttons in the toolbar. My program analyses a large file in multiple threads. I need to show how many threads are active and in which stage they are in, using QLabels in the toolbar.

Thanks.

jacek
26th February 2006, 13:58
You could try to add those labels using QToolBar::addWidget(). If you add an empty expanding QLabel first, they should be shifted to the right, but I'm not sure if it will work.

wysota
26th February 2006, 14:00
If you want to align them vertically, you'll have to put them in a layout first and add the layout to the toolbar.

prakash
3rd March 2006, 11:36
There is no function to show grid for a QTreeQidget or is't parent QTreeWiew, but QTableView does have these methods. I was confused previously so Please suggest how to drowGrid and set row height in QTreeWiget.

Thanks.:)

wysota
3rd March 2006, 11:40
Provide a custom delegate or reimplement QTreeView::drawRow.

prakash
9th March 2006, 12:03
Could you please provide me some sample code ?

Thanks.:cool:

jpn
9th March 2006, 14:06
How does a grid fit to a tree??

jpn
10th March 2006, 07:32
How does a grid fit to a tree??
...unless there are only top level items and root decoration is set to false, which means you have a multi-column list :)


Could you please provide me some sample code ?
If you use the custom delegate approach proposed by wysota:
override QItemDelegate::paint()


void MyItemDelegate::paint(QPainter* p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const
{
QItemDelegate::paint(p, opt, idx);
if (idx.isValid())
{
p->setPen(Qt::DotLine);
p->drawRect(opt.rect);
}
}

And the another approach, override QTreeView::drawRow()


void MyTreeWidget::drawRow(QPainter* p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const
{
QTreeWidget::drawRow(p, opt, idx);
for (int col = 0; col < columnCount(); ++col)
{
QModelIndex s = idx.sibling(idx.row(), col);
if (s.isValid())
{
QRect rect = visualRect(s);
p->setPen(Qt::DotLine);
p->drawRect(rect);
}

}
}