Results 1 to 8 of 8

Thread: Questions on Model/View

  1. #1
    Join Date
    Aug 2008
    Location
    Iowa, USA
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Questions on Model/View

    This is less of a question on Model/View, and much more of a question on if I'm actually understanding it correctly.

    Using a QTreeView, QStandardItemModel, and QStandardItems, I can create a tree of a bunch of text. If I want to be able to display html, my best bet is likely to subclass QStandardItem, set that as the delegate, and implement the paint function (most likely putting the String into a QTextDocument and drawing that). If I want to be able to actually click on the links that are shown, I will have to handle context menu events when users click on the QTreeView.

    Does this sound about right? I mostly just want to do what's here http://doc.trolltech.com/4.4/itemvie...treemodel.html but be able to display html tables and links.

  2. #2
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Questions on Model/View

    I am also struggling a bit with the whole model/view system but I think I can help by telling you that you are pretty much correct. The only difference is that delegates are different than standardItems. You may not even need to subclass qStandardItem because it will hold displayRole data already. Your delegate subclass, like you said, will override the paint method and look for those displayRoles and choose to draw them in a textDocument instead of ..whatever it normally uses.

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Questions on Model/View

    For html display you will need to provide a delegate (e.g. a subclass of QItemDelegate; ovewrite its paint method).
    For handling clicks (with the left mouse) button, you do not need to overwrite context menu events, but rather mouseReleaseEvent.) The only issue here being that you need to find out whether there is a link under your mouse cursor. For that (and for painting html) you might want to take a look at QAbstractTextDocumentLayout, QTextDocument and search the forums. There are some helpful threads on this topic.)

  4. #4
    Join Date
    Aug 2008
    Location
    Iowa, USA
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Questions on Model/View

    In the situation of a mouse release, it's the view that recieves that signal, correct? Then I would have to check to see what index the mouse was released over? From there, check the data of the index, make sure that data is a link to a website, and open the link? The model and the delegate don't care at all what the user does with their mice, do they?

  5. #5
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Questions on Model/View

    >In the situation of a mouse release, it's the view that recieves that signal, correct?
    Not a signal, you have to subclass the view and overwrite mouseReleasedEvent (a normal virtual function)


    > Then I would have to check to see what index the mouse was released over? From there, check the data of the index, make sure that data is a link to a website, and open the link?
    Yes.
    If the data is just the link, you can hook to the clicked() signal.
    If the data is html that contains an embedded link you need the pixel position of the click to determine whether a (and which) link is under the mouse.

    > The model and the delegate don't care at all what the user does with their mice, do they?
    Yes.

  6. #6
    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: Questions on Model/View

    Quote Originally Posted by caduel View Post
    >In the situation of a mouse release, it's the view that recieves that signal, correct?
    Not a signal, you have to subclass the view and overwrite mouseReleasedEvent (a normal virtual function)
    You don't need to touch the view. The delegate receives mouse events for the items in its editorEvent() method.


    > The model and the delegate don't care at all what the user does with their mice, do they?
    Yes.
    The delegate may care.

  7. #7
    Join Date
    Aug 2008
    Location
    Iowa, USA
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Questions on Model/View

    Quote Originally Posted by wysota View Post
    You don't need to touch the view. The delegate receives mouse events for the items in its editorEvent() method.
    This will allow me quick and easy access to the mouse events, but isn't this suppose to be used for editing? I'm not trying to edit anything at all. I'm sure it would work, I'm just wondering if this would not quite be following best practices.

  8. #8
    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: Questions on Model/View

    Quote Originally Posted by joshuajcarson View Post
    This will allow me quick and easy access to the mouse events, but isn't this suppose to be used for editing?
    No, the method name was just chosen badly. You may safely use it.

  9. The following user says thank you to wysota for this useful post:

    joshuajcarson (6th October 2008)

Similar Threads

  1. questions about datachanged() in model/view programming
    By calmspeaker in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 23:48
  2. Questions regarding setting up a Qt SQL Model/View
    By Methedrine in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2007, 09:26
  3. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 07:41
  4. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04
  5. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

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.