Results 1 to 4 of 4

Thread: Model/Views Woes

  1. #1
    Join Date
    Feb 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Model/Views Woes

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Model/Views Woes

    Quote Originally Posted by Scorp1us View Post
    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.

  3. #3
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Model/Views Woes

    I found the "Advanced Item Views" presentation from TT Dev Days 2006 very useful:
    http://www.trolltech.com/company/new...006/videolinks
    You can download the source code directly. Check out the action delegate example:
    Attached Images Attached Images

  4. The following user says thank you to spud for this useful post:

    stevey (8th February 2007)

  5. #4
    Join Date
    Aug 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model/Views Woes

    Hey Spud,

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

Similar Threads

  1. OCI w/ VS 2003 woes...
    By croftj in forum Installation and Deployment
    Replies: 5
    Last Post: 7th February 2007, 10:28
  2. MySql Stored Procedures Woes
    By stevey in forum Qt Programming
    Replies: 9
    Last Post: 19th October 2006, 12:58
  3. QGridLayout woes
    By para in forum Newbie
    Replies: 3
    Last Post: 16th October 2006, 22:41
  4. Plugin woes
    By stevey in forum Qt Programming
    Replies: 8
    Last Post: 24th July 2006, 01: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.