PDA

View Full Version : Interview: Show statusbar or other widgets in a view?



uiop21
6th March 2008, 12:34
My app has a QTreeView which consists of several column. I implemented my own Model to get the data formatted.
I would like the second column of each row to be a QStatusBar. What do I have to change? I tried changing the model, but a QVariant cannot "point" to a QStatusBar. Afterwards I read about delegates, but they can just handle input, can't they?
Do I perhaps have to subclass QTreeView? Which functions do I have to change? Does anybody perhaps have a tutorial about this?

Thank you!

jpn
6th March 2008, 13:33
Could you rephrase? Why would you like to place status bars in the second column of your view? Usually there's a single status bar which sits at the bottom of the main window. QStatusBar is a special widget which integrates nicely together Qt's model-view (Qt::StatusTipRole).

uiop21
6th March 2008, 13:37
ooops. QProgressBar is the class i want to put into my view ;-) sorry

jpn
6th March 2008, 13:43
Ahh :) See this thread: How to show progess in a QTreeView item ? (http://www.qtcentre.org/forum/f-qt-programming-2/t-how-to-show-progess-in-a-qtreeview-item--2330.html)

uiop21
6th March 2008, 15:40
Thank you very much for your help!

I used the code out of the following example: http://qtnode.net/pastebin/762

I added a if ( index.column() == 2 ) (the column that should be a progress bar). and used index.data() to get the status.
And I added setItemDelegate(new ProgressBarDelegate(0)); to my QTreeView's subclasses' ctor.

The following thing happens:
- paint() is called correctly
- if i am not in column 2, the call is redirected to the subclass by QItemDelegate::paint ( painter, option, index );
everything works fine
- if i am in the 2nd column, a new QStyleOptionProgressBar is generated and all the other code is executed. but the progressbar isn't viewed. the field where it should be just stays blank, doesn't even get colored when i select it


uiop21

uiop21
6th March 2008, 17:22
I just noticed that the code i linked to changes something!
If I use it for my Delegate, a little dot appears in the top left corner (perhaps 1x1 pixel and grey).
So the QProgressBar seems to be viewed. Does it perhaps just have the wrong size and position?

Thank you for your help!

uiop21
6th March 2008, 17:51
Sorry for the triple-posting but I found the problem!

You have to set QStyleOptionProgressBar's rect propterty to the rect property of the second argument of the function!