PDA

View Full Version : Model/Views Woes



Scorp1us
5th February 2007, 22:14
I am new to Qt Model/View. I've used others successfully though.

What I want is conceptually simple, but the code is not coming together. What I want is a view that is essentially a wrapping icon view. The same kind that is found in file browsers. I do need a custom delegate though, because there are about 6 variables that are considered in the rendering of each pixmap (decorators and such). In addition I'd like to provide on-element controls in this particular view, such as an edit [e] or remove [r] icon.


+-------+
| [img] |
| [img] |
|[e] [r]|
|[title]|
+-------+


Each one of these items I want to have laid out in a wrapping view, much like word wrap. I'd also like each item to be of variable dimensions, so a grid layout does not work well.

I was studying the docs and writing code, but then I realized that
1) I don't know how to implement the wrapping in a view
2) I don't know how to provide the mini-widgets for editing. I can draw them in the delegate's paint() just fine, but it'd be a manual process determining if a mini-widget was clicked.

I want to use model/view because of the handy proxy/sorting functionality, and I wish to have a table view where the 6 or so attributes are done with conventional widgets (combo boxes and line edits)

If anyone could point me in the right direction, I certainly would be grateful.

wysota
5th February 2007, 23:44
1) I don't know how to implement the wrapping in a view
Implement visualRect() so that it returns a rectangle where each index should be positioned. You'll have to calculate the position based on the width of the viewport and size of all items prior to the one which you calculate the position for.


2) I don't know how to provide the mini-widgets for editing. I can draw them in the delegate's paint() just fine, but it'd be a manual process determining if a mini-widget was clicked.
Yes, you should draw the controls in paint() and handle clicks in editorEvent() - process mousePress events and check the position of the cursor against the region occupied by a particular "mini widget". Then you can emit a signal or do whatever else you want.

spud
7th February 2007, 19:14
I found the "Advanced Item Views" presentation from TT Dev Days 2006 very useful:
http://www.trolltech.com/company/newsroom/events/allevents/devdays2006/videolinks
You can download the source code directly. Check out the action delegate example:

croland
8th February 2007, 04:10
Hey Spud,

Thanks for the sweet link. I'll be lucky if I can get to bed by 5 am now :D.