Results 1 to 2 of 2

Thread: Stuck with QGraphicsItem's setPos() method

Threaded View

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

    Default Re: Stuck with QGraphicsItem's setPos() method

    // HEADER FILE

    Qt Code:
    1. class exclass :public QObject, public QGraphicsItem
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. exclass(QGraphicsItem *parent = 0);
    7. QRectF boundingRect() const;
    8. void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget);
    9. private:
    10. Ui::exclassClass ui;
    11. };
    12.  
    13. class playButtonLayout : public exclass
    14. {
    15. private:
    16. QWidget *widg;
    17. QString str;
    18.  
    19. QPushButton *stopButton;
    20. QPushButton *playButton;
    21. QHBoxLayout *hboxLay;
    22.  
    23. public:
    24. playButtonLayout();
    25. QRectF boundingRect() const;
    26. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
    27. };
    To copy to clipboard, switch view to plain text mode 

    // MAIN METHOD

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QGraphicsScene scene(-200,-200,400,400);
    5. exclass *mainScene = new exclass;
    6.  
    7. mainScene->setPos(1.2,1.2);
    8. scene.addItem(mainScene);
    9. QGraphicsView view(&scene);
    10.  
    11. view.show();
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    // SOURCE FILE

    Qt Code:
    1. #include "exclass.h"
    2.  
    3. exclass::exclass(QGraphicsItem *parent): QGraphicsItem(parent)
    4. {
    5. playButtonLayout *playLayoutItem = new playButtonLayout();
    6. playLayoutItem->setPos(0,20);
    7. }
    8.  
    9.  
    10.  
    11. QRectF exclass::boundingRect() const
    12. {
    13.  
    14. }
    15.  
    16. void exclass::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
    17. {
    18.  
    19. }
    20.  
    21. playButtonLayout::playButtonLayout()
    22. {
    23. hboxLay = new QHBoxLayout;
    24. playButton = new QPushButton;
    25. stopButton = new QPushButton;
    26. widg = new QWidget;
    27. playButton->setIcon(QIcon("./images/play.JPG"));
    28. stopButton->setIcon(QIcon("./images/stop.JPG"));
    29. hboxLay->addWidget(playButton);
    30. hboxLay->addWidget(stopButton);
    31. widg->setLayout(hboxLay);
    32. str = "salman" ;
    33. }
    34.  
    35. QRectF playButtonLayout::boundingRect() const
    36. {
    37.  
    38. }
    39.  
    40. void playButtonLayout::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
    41. {}
    To copy to clipboard, switch view to plain text mode 

    I have written this code,i know that some of these things even dont make sense ,but i was trying many things and i also tried this way .....Help would be appreciated
    Last edited by wysota; 12th June 2008 at 11:26. Reason: missing [code] tags

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.