Results 1 to 3 of 3

Thread: Drawing inside Widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2013
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Drawing inside Widget

    Hi!

    I have a tree structure that I want to display inside a widget:

    Qt Code:
    1. . A
    2. / \
    3. B C
    4. / \
    5. D E
    To copy to clipboard, switch view to plain text mode 

    Here, each node (A...E) are represented by a widget containing some data about the node. These nodes are all drawn inside another QWidget, let's call it Parent, which acts similarly to a main window.

    I have managed to create and layout the nodes nicely, but I would also like to create the edges between them. Right now, my tree display looks like:

    Qt Code:
    1. . A
    2.  
    3. B C
    4.  
    5. D E
    To copy to clipboard, switch view to plain text mode 

    I'd like to hear from some experienced forum user; what is the best approach to draw these lines? I have found no "raw" drawing tools inside a QWidget (the Parent). Basically, if I could create an "EdgeWidget" that points from x1,y1 to x2,y2, I would be all set. But how do I create such a widget?

    Thanks!

    //Bobruisk

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

    Default Re: Drawing inside Widget

    Your approach of making each node a separate widget is wrong. Either draw everything (all nodes and all edges) in a single widget or use QGraphicsView where you'll be able to represent each node and each edge as a separate object. "Elastic Nodes" example can help you with that approach.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2013
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drawing inside Widget

    I will look into that, thank you!

    //Bobruisk

Similar Threads

  1. Replies: 8
    Last Post: 2nd February 2012, 19:52
  2. Replies: 5
    Last Post: 14th December 2011, 11:51
  3. Replies: 8
    Last Post: 28th June 2011, 14:57
  4. Drawing widgets inside a Qt application
    By aughey in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2010, 08:45
  5. Drawing QImage inside QTextDocument
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2009, 07:52

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
  •  
Qt is a trademark of The Qt Company.