Results 1 to 13 of 13

Thread: [qt-4.2] question on QAbstractItemView

  1. #1
    Join Date
    Dec 2006
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [qt-4.2] question on QAbstractItemView

    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:aint(...) but I can't understand how

  2. #2
    Join Date
    Dec 2006
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [qt-4.2] question on QAbstractItemView

    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?

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

    Default Re: [qt-4.2] question on QAbstractItemView

    Quote Originally Posted by someralex View Post
    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.

  4. #4
    Join Date
    Dec 2006
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [qt-4.2] question on QAbstractItemView

    An example says more than a thousand words
    I would be very grateful for the example.

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

    Default Re: [qt-4.2] question on QAbstractItemView

    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.

  6. #6
    Join Date
    Dec 2006
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [qt-4.2] question on QAbstractItemView

    Quote Originally Posted by wysota View Post
    Use the scrollTo() method along with QAbstractItemView::PositionAtCenter scroll hint.
    What can i set QAbstractItemView::PositionAtCenter for QListView ?

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

    Default Re: [qt-4.2] question on QAbstractItemView

    Did you even bother to take a look at QAbstractItemView::scrollTo() docs? The hint mentioned is one of its arguments...

  8. #8
    Join Date
    Dec 2006
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [qt-4.2] question on QAbstractItemView

    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?

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

    Default Re: [qt-4.2] question on QAbstractItemView

    But why create an own view? You have to use the scrollTo() method, not reimplement it.

  10. #10
    Join Date
    Dec 2006
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [qt-4.2] question on QAbstractItemView

    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.

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

    Default Re: [qt-4.2] question on QAbstractItemView

    Quote Originally Posted by someralex View Post
    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.

  12. #12
    Join Date
    Dec 2006
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [qt-4.2] question on QAbstractItemView

    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?

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

    Default Re: [qt-4.2] question on QAbstractItemView

    Quote Originally Posted by someralex View Post
    Where should I add the additional items? Into the model? How do I do that?
    Hmm... the same way you added the original items?

    and what routines exactly I need to reimplement in the created class, based on QListView?
    At least the paint event and visualRect.

Similar Threads

  1. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 14:38
  2. setContentsMargins in QAbstractItemView
    By Promethee in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2006, 14:40

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
  •  
Qt is a trademark of The Qt Company.