Results 1 to 2 of 2

Thread: Best way to implement "floating controls" for a QGraphicsView?

  1. #1
    Join Date
    Jun 2009
    Posts
    6
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Best way to implement "floating controls" for a QGraphicsView?

    I have a QGraphicsView subclass which lets the user examine the scene contents by zooming in/out, panning, etc.

    I would now like to provide controls that are shown on top of the graphics view area (near the borders/corners mostly), and after reading a lot of Qt documentation I'm still not sure how one would accomplish this.

    The kind of controls I'm thinking about are, for example:
    • a little scale showing how many pixels 1 logical unit is wide under the current zoom level. (should have interactive capabilities too, like more info when hovering, context menu with actions to choose the logical unit, etc.)
    • little magnifying class icons which initiate zooming in/out when clicked
    • informational icons popping up to give feedback on special things occuring while the user works with the view's contents
    • and more...


    The important thing is that their geometry should not be affected by modifications to the viewport geometry, so they can't be QGraphicsItems inside the scene.

    Also, I don't like the idea of drawing the controls in a reimplemented QGraphicsView::drawForeground function, because this works in scene coordinates, requiring all content (also pixmap icons and such) to be scaled to scene coordinates in order to draw them, only for the view to internally scale them back to screen coordinates. Also, implementing interactive capabilities would be cumbersome and require reproducing functionality already provided with QWidget (and also QGraphicsItem).

    I have tried manually adding child widgets (QWidget!) to the graphics view (by calling QWidget::setParent on the widgets), but QGraphicsView seems to suppress them.

    Is there a way to force it to show these wigdets?
    That would be the best solution as far as I can see.

  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: Best way to implement "floating controls" for a QGraphicsView?

    Probably the easiest way is to just add real widgets to the viewport and set their geometry upon changes to the viewport's geometry. Note that you need to add the widgets to the viewport and not the view.
    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.


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.