Results 1 to 4 of 4

Thread: Is the model/view architecture needed for a small widget?

  1. #1
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Is the model/view architecture needed for a small widget?

    Hi,

    For my first custom editor, like to implement a star-rating widget (similar to the one in http://doc.trolltech.com/4.5/itemvie...rdelegate.html) as part of a dialog. The widget is for collecting numerical info, and technically, I could use a QComboBox instead. However, I wanted something that looked nicer and used one less click than a QComboBox.

    I was wondering, is a full-fledged model/view-delegate approach needed? Trolltech's example (the StarDelegate class) requires the passing of QStyleOptionViewItem, QAbstractItemModel, and QModelIndex, which feels excessive (at first glance, at least) for the selection and display of one number. Is it a good idea to just pass the value between the viewer and the editor? If so, are there any classes that help me to make a simpler implementation?

    Any advice would be much appreciated, thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Is the model/view architecture needed for a small widget?

    Where should that star widget be? Do you have already a model in that dialog? If you haven't a model and it is just a normal dialog collecting data, then I would simply overwrite the paint event of a QWidget and fetch mouse presses and calculate how many stars for that particular mouse position. And of course a setter and getter method...

  3. The following user says thank you to Lykurg for this useful post:

    hackerNovitiate (30th March 2010)

  4. #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: Is the model/view architecture needed for a small widget?

    What kind of is your editor ? Does it have columns ?
    You could use either of QTableWidget or QTreeWidget with delegates.

    Other way could be - Use the StarEditor class from the star delegate example. Its a complete class in itself and you can use the wheel, cant you

  5. #4
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is the model/view architecture needed for a small widget?

    Quote Originally Posted by Lykurg View Post
    If you haven't a model and it is just a normal dialog collecting data, then I would simply overwrite the paint event of a QWidget and fetch mouse presses and calculate how many stars for that particular mouse position. And of course a setter and getter method...
    I used this suggestion; it works beautifully now! And I familiarized myself with QPainter and mouse event handling in the process. Thanks!

    Quote Originally Posted by aamer4yu View Post
    What kind of is your editor ? Does it have columns ?
    You could use either of QTableWidget or QTreeWidget with delegates.
    No columns, just a "how many stars out of 3?" widget.

    Other way could be - Use the StarEditor class from the star delegate example. Its a complete class in itself and you can use the wheel, cant you
    Yeah, that's true But I didn't for 3 reasons: i) I was wondering if the complete model/view architecture was too complex for the simple widget I wanted. ii) I'm still not sure under what licence I want to release my program, so I thought it's best not to copy Nokia's code. iii) This is also a learning project, so I wanted to build my own stuff. Thanks for the suggestion, nonetheless!

Similar Threads

  1. Replies: 1
    Last Post: 1st February 2010, 18:42
  2. Advice needed for QT application architecture
    By hubbobubbo in forum Qt Programming
    Replies: 0
    Last Post: 14th December 2009, 11:30
  3. modal/view architecture
    By sonuani in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2008, 05:39
  4. Replies: 1
    Last Post: 30th November 2007, 11:55
  5. Replies: 1
    Last Post: 1st March 2006, 11:43

Tags for this Thread

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.