Results 1 to 8 of 8

Thread: QWidget in a QGraphicsScene ..!!!

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QWidget in a QGraphicsScene ..!!!

    HI
    The below code must show a button in a scene ,but the scene shows a widget in a scene with no button ,it seems as if only a widget is created but widget remains empty...any IDEA !!

    Qt Code:
    1. class MainScene:public QGraphicsScene
    2. {
    3. public:
    4. QGraphicsProxyWidget *proxy;
    5. Navigation *navigate;
    6. MainScene();
    7.  
    8. void displayNavigationStatus();
    9. virtual ~MainScene();
    10. };
    11.  
    12.  
    13. MainScene::MainScene()
    14. {
    15. navigate = new Navigation;
    16. displayNavigationStatus();
    17. }
    18.  
    19. void MainScene::displayNavigationStatus()
    20. {
    21. proxy = addWidget(navigate);
    22. }
    23.  
    24. MainScene::~MainScene()
    25. {
    26. }
    27.  
    28. class Navigation:public QWidget
    29. {
    30.  
    31. public:
    32. Navigation();
    33. ~Navigation();
    34.  
    35. private:
    36. QSize buttonIconSize;
    37.  
    38. QPushButton *backButton ;
    39.  
    40. void setBackButton();
    41.  
    42. };
    43.  
    44. #include "Navigation.h"
    45.  
    46. Navigation::Navigation()
    47. {
    48. backButton = new QPushButton();
    49. setBackButton();
    50.  
    51. }
    52. void Navigation::setBackButton()
    53. {
    54. backButton->setIcon(QIcon(BACKBUTTON_DIR_LOCATION));
    55. backButton->setIconSize(buttonIconSize);
    56. backButton->setGeometry(BACK_BUTTON_X,BACK_BUTTON_Y,BUTTON_PARAM,BUTTON_PARAM);
    57.  
    58. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget in a QGraphicsScene ..!!!

    try this

    Qt Code:
    1. backButton = new QPushButton(this);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget in a QGraphicsScene ..!!!

    No difference..still only the grey screen..

  4. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget in a QGraphicsScene ..!!!

    any help.!!!

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QWidget in a QGraphicsScene ..!!!

    try calling backButton->show();
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget in a QGraphicsScene ..!!!

    still no difference..!!

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QWidget in a QGraphicsScene ..!!!

    The below code must show a button in a scene
    Your code however suggest a widget in a scene, *in* which a button is located.
    If you try to show this widget normally (not in a scene) does the button show then?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    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

    Post Re: QWidget in a QGraphicsScene ..!!!

    Agree with high_flyer

    Also in
    Qt Code:
    1. void Navigation::setBackButton()
    2. {
    3. backButton->setIcon(QIcon(BACKBUTTON_DIR_LOCATION));
    4. backButton->setIconSize(buttonIconSize);
    5. backButton->setGeometry(BACK_BUTTON_X,BACK_BUTTON_Y,BUTTON_PARAM,BUTTON_PARAM);
    6. }
    To copy to clipboard, switch view to plain text mode 

    make sure the geometry u set is proper. May be they are not getting initialised properly

Similar Threads

  1. QWidget in QGraphicsScene not drawing
    By stevel in forum Qt Programming
    Replies: 3
    Last Post: 19th September 2008, 19:19
  2. Error in put one QWidget in another QWidget
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 16:05
  3. Replies: 3
    Last Post: 8th March 2007, 14:54
  4. When to use QGraphicsScene or QWidget
    By fossill in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2007, 23:58
  5. QWidget item in QGraphicsScene
    By IUnknown in forum Qt Programming
    Replies: 4
    Last Post: 4th November 2006, 00:05

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.