Results 1 to 2 of 2

Thread: Custom widget in list view

  1. #1
    Join Date
    Nov 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy Custom widget in list view

    I'm just starting to learn Qt and my c++/programming skills in general are a little rusty. A friend and I are writing a simple asset management application. I'm charged with programming the GUI.

    My problem is:

    I want to be able to create my own unique look for the thumbnail when I view all images. I can create my own widget and override the paintEvent() function to create what I want. But how can I use this widget in a list view (or any view for that matter).

    From what I've been reading, especially on this forum, is to derive my own delegate (espcially if the content may be dynamically updated). For now, lets assume static content. I've also read using QAbstractItemView::setIndexWidget() but I cannot for the life of me figure out where to put the call and how to properly format it. Where do I get the QModelIndex from??

    I'm basing my code right now off the Puzzle example from Trolltech, using the model-view architecture (which is a little confusing to me, too)

    For example:

    I have a mainwindow which sets up the layout and menus.
    mainwindow also sets up a QListView and sets many of its options.
    I have a model called AssetModel acting on my QListView. It stores the data in a QList<QPixmap>.

    Right now, i can add images to my model, and they get displayed in the QListView. It works, but is not very pretty.

    I also have a customWidget (right now all it does is paint a purple square), but lets say instead of adding an image to the QListView, I would like to add my customWidget instead. How do I go about this?

    Also, in general, in trying to follow how the model-view code is working...Where is data() being called from? inside my QListView? I notice the ability to call data() with a userRole? To use the userRole, would I have to implement my own ListView?

    I know this is a large post, but I really want to understand.

    Thank you for any help or direction...

    -Kevin-

    p.s. I can post code if you want.

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget in list view

    You call data from your delegate when you paint your information.

Similar Threads

  1. Replies: 1
    Last Post: 5th November 2006, 23:50
  2. Problem applying setWindowOpacity to a custom Widget
    By yellowmat in forum Qt Programming
    Replies: 8
    Last Post: 1st November 2006, 10:05
  3. Replies: 3
    Last Post: 12th April 2006, 08:20
  4. Replies: 4
    Last Post: 24th March 2006, 22:50
  5. Replies: 4
    Last Post: 6th February 2006, 14:30

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.