Results 1 to 7 of 7

Thread: How to build a list of custom widgets

  1. #1
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt Jambi
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default How to build a list of custom widgets

    Hi,

    I would like to create a list of custom widgets, each composed of 2 rows and 3 columns. The left and middle columns will contain text in each row and the right one will contain an icon spanning on both rows.

    What is the best approach?

    What I've done is to create a Widget containing a ListView and another Widget (which will certainly be a Table) that should be used as rows of the ListView.

    I've read somewhere to use the setIndexWidget method but I don't exactly know how to use it.

    Suppose I have a model containing the data to display, where shall the ListView be populated and how?

    I would be really grateful if someone could provide a little example!

    Thanks in advance!

  2. #2
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt Jambi
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: How to build a list of custom widgets

    By the way, I'm using Qt Jambi.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to build a list of custom widgets

    Will your text have editing options ?
    also is 2 rows and 3 columns fixed ?

    If yes I dont see need for QTableview.. you can do the following -
    create 4 labels for text and 1 label for icon and place them in a grid layout. and apply the grid layout to your main custom widget
    thats it.. !!

  4. #4
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt Jambi
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: How to build a list of custom widgets

    Okay, I see your point but I want the icon to span the 2 rows, can I do it using Grid Layout?

    Moreover, do you know how I can insert my custom widget into my ListView?

    Thanks.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to build a list of custom widgets

    but I want the icon to span the 2 rows, can I do it using Grid Layout?
    Sure. Read documentation for QGridLayout
    Why do you want to use ListView ? inserting custom widget is heavy and should not be done for many cells..
    Whats your requirement ?

  6. #6
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt Jambi
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: How to build a list of custom widgets

    What I want is to build a list. The problem is that it is not a basic list.

    Every element of this list must be composed of the layout previously described (some text on the left, in the middle and an icon on the right)

    This is how a single element of the list should look like:

    | text here ################################ text here ### ICON |
    | other text here (might be in different style) ##### text here ### ICON |

    The ICON spans the 2 rows.

    So my idea was to build a widget representing a single element of the list and then add several widgets to the list.

    Please tell me if something is still not clear.

    Thanks again.

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to build a list of custom widgets

    It would be better if you go for delegates then. See QItemDelegateIn the paint function you can calculate the rects yourself and draw text and place icons as per your requirement.

    Other ways wont be as efficient as using delegates. Also see setItemData with which you can set different text you need..

Similar Threads

  1. Replies: 1
    Last Post: 18th July 2012, 09:59
  2. List of child widgets includes layout
    By JovianGhost in forum Qt Programming
    Replies: 5
    Last Post: 11th May 2010, 03:22
  3. Replies: 0
    Last Post: 15th May 2009, 15:38
  4. List of Widgets
    By linuxdev in forum Qt Tools
    Replies: 3
    Last Post: 30th April 2009, 14:24
  5. Custom widget in list view
    By fusoin23 in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2006, 14:09

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.