Results 1 to 12 of 12

Thread: QGraphicsScene...How to have your own format for button,etc..???

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QGraphicsScene...How to have your own format for button,etc..???

    To be honest your code doesn't make much sense and is invalid and won't work... Those methods you have to implement are there for a reason, you can't leave them empty.

    Why not do it this way?
    Qt Code:
    1. int main(int argc, char **argv){
    2. QApplication app(argc, argv);
    3. QGraphicsScene *scene = new QGraphicsScene(&view);
    4. view.setScene(scene);
    5. QWidget *wgt = new QWidget;
    6. QHBoxLayout *l = new QHBoxLayout(wgt);
    7. l->addWidget(new QPushButton("play"));
    8. l->addWidget(new QPushButton("stop"));
    9. QGraphicsProxyWidget *wgtItem = scene->addWidget(wgt);
    10. QGraphicsTextItem *txtItem = scene->addText("salman");
    11. wgtItem->setPos(100,100);
    12. txtItem->setPos(200, 300);
    13. view.show();
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QGraphicsScene...How to have your own format for button,etc..???

    Ya,thanks,great,not only the problem is solved but things are also clear..
    In your code you implemented a Widget in main function itself ,it worked fine...
    i tried to make a class derived from QWidget and define the play and stop button there and called the object of that class in main

    exclass *lay = new exclass;

    QGraphicsProxyWidget *widgItem = scene->addWidget(lay);

    widgItem->setPos(20,20);

    but in this case it shows an empty gray screen with in my view which has purple background...

Similar Threads

  1. Is there a known problem with QMimeData on Mac OS X?
    By Wurgl in forum Qt Programming
    Replies: 8
    Last Post: 27th February 2008, 22:21
  2. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48

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.