Results 1 to 4 of 4

Thread: overriding QListWidget advice

  1. #1
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default overriding QListWidget advice

    I would like to implement a cylinder like list. For that purpose I override QListWidget.

    The way it works is: after items added (number of items must be bigger then the number of items that could be displayed in viewport) and call show() widget creates extra items (function is called in resize event), that way you get a fill of infinitum loop. Selected item is alway in the center of widget.

    Example:
    Viewport: 5 items
    List: 10 items
    Extra items: 3 at start (last 3 of the list) and 3 at the end (first 3 of the list)
    When selected item is 10 item of the list, next selected item is first item of the list.

    I haven't figured out how to handle the situation where there are less intems than the item that could be displayed in viewport. The consequence of that problem is after calling clear() how to handle adding items.

    the only idea i have is create a list with empty items and while adding an item remove empty one.

    Any advice?

    PS: hope my English is understandable.

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

    Default Re: overriding QListWidget advice

    QListWidget is not well suited for such a situation. Implementing a custom widget (based on QFrame or QAbstractScrollArea) would be a better approach, in my opinion. If you start manipulating items like you are doing it now, the scrollbar value will make no sense and in border situations (like the one you mention) there will be no viable solution. With a custom widget you could overcome the weaknesses. It's only a matter of deciding how much functionality of QListWidget you really need.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: overriding QListWidget advice

    functionality i need from QListWidget are:
    - container
    - selection (user events and in code)

    That's why I find QListWidget useful. I'll do a research about your advice.

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

    Default Re: overriding QListWidget advice

    If all you want is to show a bunch of items with ability to select a subset of them then forget about QListWidget and implement something simpler.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 5th July 2010, 21:53
  2. Overriding drawRubberBand()
    By andrew.nguyen in forum Qwt
    Replies: 3
    Last Post: 21st April 2010, 06:58
  3. Overriding QListView painting
    By efegea in forum Qt Programming
    Replies: 2
    Last Post: 29th November 2008, 17:16
  4. Overriding shortcuts for QGraphicsItems
    By pherthyl in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2008, 22:47
  5. overriding the QWidget::contextMenuEvent
    By smarinr in forum Qt Programming
    Replies: 1
    Last Post: 9th May 2008, 21:16

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.