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!
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...
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 :rolleyes:
Re: Is the model/view architecture needed for a small widget?
Quote:
Originally Posted by
Lykurg
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
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.
Quote:
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 :rolleyes:
Yeah, that's true :D 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!