Results 1 to 5 of 5

Thread: Anchor widgets in QGraphicsScene

  1. #1
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Anchor widgets in QGraphicsScene

    I am trying create a multitouch game table with a control area for each player and the game master.

    table_top_mockup.jpg

    I want to have a graphics scene that contains the map and can be zoomed in and out and translated. I think I also need the control widgets in the scene because I want to rotate them according to the side of the table they are on. I am wondering if there is a way to anchor the widgets around the QGraphicsView according to the picture and not have them move or change size when I zoom or translate the QGraphicsView.

  2. #2
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Anchor widgets in QGraphicsScene

    I think I figured out a solution. I created a QGraphicsView and added a QGraphicsScene that contained the control widgets. Then I created another QGraphicsView with a QGraphicsScene that contains the map I want to display. I then add the QGraphicsView with the map to the QGraphicsScene with the controls and set it below the control widgets. Now I can scroll and zoom my map yet keep my control widgets in place with the correct orientation. Does anyone see an issue with this method?

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Anchor widgets in QGraphicsScene

    I created a QGraphicsView and added a QGraphicsScene that contained the control widgets.
    You could have simply made the control widgets as child widgets of the graphics view, if the control widgets are not some graphics items.
    And if the control widgets are graphics items, then theres QGraphicsItem::ItemIgnoresTransformations flag in QGraphicsItem

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

    johnsoga (18th February 2010)

  5. #4
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Anchor widgets in QGraphicsScene

    You could have simply made the control widgets as child widgets of the graphics view
    I need to rotate the widgets based on which side of the table they are on, that is why I need to have them in a graphics scene

    theres QGraphicsItem::ItemIgnoresTransformations flag in QGraphicsItem
    This is exactly what I was look for, I will see if it works the way I expect.

  6. #5
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Anchor widgets in QGraphicsScene

    I set the flag QGraphicsItem::ItemIgnoresTransformations and that keeps the widget from scaling when I scale the view but when I pan around the widget doesn't stay in view. If i set the widget's parent to the view then I can't rotate the widget. How can I keep the widget that I add to a scene from scaling and moving with the scene? Following is the code I am using to add the widget to the scene, I added a very large pixmap to the scene first so this is after that:

    Qt Code:
    1. QPushButton *button = new QPushButton( "Hello World" );
    2. button->move( 300, 300 );
    3. button->setFixedSize( 200, 200 );
    4. QGraphicsProxyWidget *proxy = view.scene()->addWidget( button );
    5. proxy->setFlag( QGraphicsItem::ItemIgnoresTransformations, true );
    6. proxy->rotate( 180 );
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Gabe

Similar Threads

  1. Replies: 1
    Last Post: 2nd September 2009, 14:07
  2. QWebView and scrolling to anchor
    By serenti in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2009, 16:55
  3. Replies: 0
    Last Post: 15th May 2009, 15:38
  4. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 17:27
  5. Replies: 2
    Last Post: 15th March 2006, 12:13

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.