Results 1 to 4 of 4

Thread: How to use QGraphicsView in designer

  1. #1
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to use QGraphicsView in designer

    Hi,

    I have created a user interface by code (not using designer). I created a custom QGraphicsView and add all widgets to it, did override mousewheel event to support zoom in and zoom out. But now I have to do the same thing using designer.
    So I drop a QGraphicsView in Mainwindow and promote it to my custom class. Then I drop couple of push buttons on it and try to run. The scaling doesn't work now. The other change I have now is am passing a QWidget as argument to QGraphicsView constructor instead of QGraphicsScene. Is that the reason that scaling stopped working?

    Also how can I add widgets to QGraphicsView (using designer) so that I can scale them?

    Thanks.

  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: How to use QGraphicsView in designer

    Quote Originally Posted by dpatel View Post
    Also how can I add widgets to QGraphicsView (using designer) so that I can scale them?
    The view displays (and scales) the contents of the scene. Dropping widgets on a graphics view in Designer doesn't add them to the scene. Designer can't populate the scene for you, you need to do it in code.
    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. The following user says thank you to wysota for this useful post:

    dpatel (6th June 2011)

  4. #3
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QGraphicsView in designer

    Thanks wysota for the information.

    After seeing your reply I tried following code but I don't see any widgets that I placed on the MainWindow, only the graphics view with white background which covers all main windows is shown.

    Qt Code:
    1. m_pGraphicsView=new QGraphicsView(pScene);
    2. pScene->addWidget(this->centralWidget());
    3.  
    4. //ui.d->setVisible(false);
    5. setCentralWidget(m_pGraphicsView);
    To copy to clipboard, switch view to plain text mode 

    I have added the code in QMainWindow's constructor just after ui.setup(this) call. Can you please tell me why its not working. Is there any way I can do it?

    D.
    Last edited by dpatel; 6th June 2011 at 11:44. Reason: updated contents

  5. #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: How to use QGraphicsView in designer

    Try analyzing the code you have written, it doesn't make sense. It's like you had a yellow box and a red box and you put the red box in the yellow box and then you'd like to place that yellow box (containing the red box) in the red box.
    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.


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

    dpatel (10th June 2011)

Similar Threads

  1. Overiding QGraphicsView events with Designer
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 26th July 2011, 08:34
  2. Replies: 1
    Last Post: 8th September 2010, 19:31
  3. Replies: 2
    Last Post: 1st October 2009, 16:26
  4. Designer plugin segfaults designer :(
    By tmarki in forum Qt Tools
    Replies: 4
    Last Post: 26th September 2007, 11:22
  5. Replies: 1
    Last Post: 22nd January 2007, 12:13

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.