Results 1 to 12 of 12

Thread: QTreeModel Items to a Widget

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeModel Items to a Widget

    My app is an interface to a system in which i represented all command and response available in a QTreeModel style. Representation example below
    // command tree
    Commands
    |__Device1
    | |__SignatureRq
    | | |__Opcode
    | |
    | |__AnotherRqForThisDevice
    | |__data for this Req
    | |__data for this Req
    |__ Device2
    |__SignatureWriteRq
    | |__SerialNo
    | |__Manufacturing Date
    | |__FirmwareVersion
    |
    |__AnotherRqForThisDevice
    |__data for this Req

    // response tree
    Response
    |__Device1
    | |__SignatureRsp
    | | |__SerialNo
    | | |__Manufacturing Date
    | | |__FirmwareVersion
    | |
    | |__AnotherRspForThisDevice
    | |__data for this Rsp
    |__ Device2
    |__SignatureRsp
    | |__SerialNo
    | |__Manufacturing Date
    | |__FirmwareVersion
    |
    |__AnotherRspForThisDevice
    |__data for this Rsp
    User can click a command item of a certain device and click a send command button and look at the response at the coresponding response from the device at the response tree...

    Now, this style is good for the engineering user for they know what request to use and what response to look for in the response tree but I was ask to make an interface for the normal user then came my problem. I would like to somehow create a widget that represent each device and pick some not all the command and show the response in a user firendly fashion. I would like to use my tree model as the backbone of this interface so that if the designer decides to add or delete some command ill just edit my tree and my interface will adjust.

    My million dollar question is

    can I somehow link a widget to represent an Item including its children of my model? notice that the devices ( device 1 and so on ) is always the child of COMMAND/RESPONSE Item in my model, and the children of my devices is the available command or response depending on which model you are looking.

    What is the easiest way to implement this goal? I was planning to use a delegate to somehow draw my Widget so i will still have a tree like view as viewer.

    Is there any other simple way to achieve my goal?

    Lastly, Did you guys have a good holiday season ?

    baray98

  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: QTreeModel Items to a Widget

    I suggest you have a hidden role that will tell you the type of each argument of each command and simply have a component that will build widgets according to the information stored in the model. The functionality will be close to what property browsers offer only that the visual representation will be different.

    Take a look at this:
    http://doc.trolltech.com/qq/qq13-attributes.html

  3. #3
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeModel Items to a Widget

    I did some reading on that document but when i tried the source it won't compile on me the problem is that qvaluevector.h is missing. well well anyways my understanding is still not clear of what is needed to be done . Any more links and example which I can study on or better yet you can explain a little bit of some idea in how my problem be solved.

    thanks for your reply wyosota, i love you man .......

    still reading some qt docs,
    baray98

  4. #4
    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: QTreeModel Items to a Widget

    The code is for Qt3. You have to port it to Qt4. I wanted to show you the idea, not a final solution.

  5. #5
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeModel Items to a Widget

    thats what i tought its qt3 but.. thank you for the link . I want some more examples or explainations , hoping a way to solve this problem.

    baray98

  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: QTreeModel Items to a Widget

    If you like the approach then simply port the code. It should take no more than 10 minutes to do it.

  7. #7
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeModel Items to a Widget

    What i would like to do is to draw a widget in tree like fashion ie:

    Device1
    ----------
    | |
    | |----------Device 2
    | |
    | |-------------Device 3
    |
    |
    Device 4
    |_______Device5
    |_______Device 5
    The user can click on the "device widget" and another widget will pop-up showing its signature and some other info that is neccessary. All this widget and the poping widget should all be dynamically build according to the info in my models , by the way i can adjust the data in my model to hold more info to build my widgets.

    Is there any more idea on how to do implement this , I've been reading a lot today and still no idea how will i implement this.

    I dont even know how to draw those device widget in a tree like fashion.

    I am super tired now I have to sleep, talk you later guys
    baray98

  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: QTreeModel Items to a Widget

    Can't you implement it like in the example I gave you? It's all there - the "attributes" are your tree items. Simply fetch data from the tree and fill in the dialog. Is there a specific implementation problem you are facing or a simple lack of concept?

    As for the tree - use a tree view with a model that will map devices to nodes. Everything else will be handled by the architecture.

  9. #9
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeModel Items to a Widget

    I have both problems. yes, I can implement it with the "attributes" style and this will serve as my popping widget everytime my user click on a dvice widget.

    Now, my specific problem for now is that how can i insert a widget as a node in treeview? I wanted it to be a widget so that i can implement the right and left click if I want. I tried the treeview->style()->drawControl() but there is no signal out from widget that i have drawn, where i can connect my showing of my "attributes" widget slot.

    thank you for your insights wyosota...

    baray98

  10. #10
    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: QTreeModel Items to a Widget

    It doesn't have to be a widget. You can do it though signals or delegates. See docs for QAbstractItemDelegate and friends.

  11. #11
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeModel Items to a Widget

    all i can see in the delegate is

    Qt Code:
    1. QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
    To copy to clipboard, switch view to plain text mode 

    if i will use this then everytim my user trigger the edit then i will pop-up my "attribute" window correct?

    I was thinking of giving my user contextMenu on right click of widget devices and there will be an option like "properties" then show the attribute window. is this doable? is there something i miss on delegates?

    baray98

  12. #12
    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: QTreeModel Items to a Widget

    QAbstractItemDelegate::paint() and QAbstractItemDelegate::editorEvent() are the things to look at.

    As for the menu, you can always subclass the widget and reimplement its context menu event, but going through the delegate is fine too.

Similar Threads

  1. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  2. Controlling which widget on top layer?
    By JonathanForQT4 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2007, 14:27
  3. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 21:28
  4. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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.