PDA

View Full Version : [qt-4.2] question on QAbstractItemView



someralex
16th December 2006, 17:29
How do I make the list (based on QAbstractItemView or any other) so all the items in it would display as specific graphical images or do I need to paint with primitives each and every item?
I need to make an individual appearance for every item in the visible area of the list and also an individual appearance for the active item.
How do I make such a thing?
P.S. I guess I need to do it with QAbstractItemDelegate::paint(...) but I can't understand how :confused:

someralex
17th December 2006, 15:33
I figured out QItemDelegate. It appears that I can set appearance for both active and inactive item. And I need to set appearance for any needed item in the visible area, for example the upper and the lower items need to have their own definite appearance.
And the second question - how to make Selected_item stay in the center unmovable and list to scroll corresponding to the active item?

wysota
17th December 2006, 16:10
And the second question - how to make Selected_item stay in the center unmovable and list to scroll corresponding to the active item?

Use the scrollTo() method along with QAbstractItemView::PositionAtCenter scroll hint.

someralex
17th December 2006, 20:32
An example says more than a thousand words ;)
I would be very grateful for the example.

wysota
17th December 2006, 21:10
You want an example of the use of a single method? Just call it from a slot connected to the scrollbars. The only difficulty is to calculate the new selected index when the scrollbar is clicked.

someralex
18th December 2006, 11:28
Use the scrollTo() method along with QAbstractItemView::PositionAtCenter scroll hint.

What can i set QAbstractItemView::PositionAtCenter for QListView ?

wysota
18th December 2006, 12:34
Did you even bother to take a look at QAbstractItemView::scrollTo() docs? The hint mentioned is one of its arguments...

someralex
18th December 2006, 15:09
I have read everything possible, I just don't get how to realize the child class based on QAbstractItemView. Can you tell me what is the minimal set of obligatory methods for realizing my own ListView? Is it enough to create own class based on QListView and to re-denote only scrollTo method in it? How to accomplish it better?

wysota
18th December 2006, 17:15
But why create an own view? You have to use the scrollTo() method, not reimplement it.

someralex
19th December 2006, 13:04
Thanks, I managed to do scrollTo. But it came out not quite the way I wanted.
For example we have the list:
item_1
item_2
item_3
item_4
item_5
item_6
item_7
item_8
only 5 items fit into QListView list in my app, so after launch my ListView should look like this:
---------------------------
| item_7 |
| item_8 |
|--------------------------|
| item_1 |
|--------------------------|
| item_2 |
| item_3 |
---------------------------|

So the list must croll around and the central item should stay in the middle unmovable. How do I do it?
May be
void QListView::indexesMoved ( const QModelIndexList & indexes ) [signal]
void QListView::setPositionForIndex ( const QPoint & position, const QModelIndex & index ) [protected]
Or is there any other way? Please help.

wysota
19th December 2006, 14:35
So the list must croll around and the central item should stay in the middle unmovable.
Oh, you didn't mention that "detail" before :)


How do I do it?
Good question :) The easiest way is to add additional items. The proper way is probably to subclass the view and reimplement the painting and positioning routines.

someralex
19th December 2006, 15:16
The easiest way is to add additional items.
Where should I add the additional items? Into the model? How do I do that?

The proper way is probably to subclass the view and reimplement the painting and positioning routines.
and what routines exactly I need to reimplement in the created class, based on QListView?

wysota
19th December 2006, 15:41
Where should I add the additional items? Into the model? How do I do that?
Hmm... the same way you added the original items? :rolleyes:


and what routines exactly I need to reimplement in the created class, based on QListView?

At least the paint event and visualRect.