Results 1 to 12 of 12

Thread: QGraphicsView

  1. #1
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsView

    I derive a subclass from QMainWindow, I want to set the QGraphicsView object as the mainwindow's centralWidget, like below:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. test w;
    5. w.show();
    6. a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    7. return a.exec();
    8. }
    9.  
    10. test::test(QWidget *parent, Qt::WFlags flags)
    11. : QMainWindow(parent, flags)
    12. {
    13. ui.setupUi(this);
    14.  
    15. QPixmap pixCT;
    16. pixCT.load("Resources/CT.bmp");
    17. QGraphicsView view(&scene, this);
    18. setCentralWidget(&view);
    19. scene.addPixmap(pixCT);
    20. //view.show();
    21. }
    To copy to clipboard, switch view to plain text mode 

    But it doesn't work. What should I do to solve this problem ?

    Thank you very much for helping!

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView

    You're creating the scene and the view locally in the constructor of test. Therefore they are destroyed after the constructor returns.

    The solution is to either make them members of test or creating them dynamically in the constructor.

    Regards

  3. The following user says thank you to marcel for this useful post:

    Shawn (1st June 2007)

  4. #3
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView

    hehe

    Thanks ! a silly mistake...

    I made them members and got passed.

    BTW, after
    Qt Code:
    1. scene.addPixmap(pixCT);
    To copy to clipboard, switch view to plain text mode 
    is there any way I can control its position? is there some function like view.draw(&pixmap, x, y) or scene.addPixmap(&pixmap, x, y)?

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView

    is there any way I can control its position? is there some function like view.draw(&pixmap, x, y) or scene.addPixmap(&pixmap, x, y)?
    No, not like this.
    Add pixmap return a QGraphicsPixmapItem. You can play with this - translate it, rotate it, scale it, etc.

    Regards

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

    Shawn (1st June 2007)

  7. #5
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView

    I look through the QGraphicsPixmapItem reference but still have no idea...

    Would you please give me a small example for showing pixmap at (x, y ) in QGraphicsView ? I 'd be very appreciate of that if you would.

    I have read the code of example "exportedcanvas", it's a lillte too "large" for me...

  8. #6
    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: QGraphicsView


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

    Shawn (1st June 2007)

  10. #7
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView

    Quote Originally Posted by wysota View Post
    It acts very strange when I using this setPos()

    Qt Code:
    1. class test : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. test(QWidget *parent = 0, Qt::WFlags flags = 0);
    7. ~test();
    8.  
    9. private:
    10. Ui::testClass ui;
    11.  
    12. };
    13.  
    14. test::test(QWidget *parent, Qt::WFlags flags)
    15. : QMainWindow(parent, flags)
    16. {
    17. ui.setupUi(this);
    18.  
    19. QPixmap pixTrans;
    20. pixTrans.load("Resources/Trans.bmp");
    21.  
    22. view.setScene(&scene);
    23. setCentralWidget(&view);
    24.  
    25. QGraphicsPixmapItem* i = scene.addPixmap(pixTrans);
    26. i->setPos(-200,-200);
    27. }
    To copy to clipboard, switch view to plain text mode 

    before I using this setPos, the central point of the image is at (300,200) (because the size of centralWidget is 600*400);
    after I using this setPos(-200,-200), the central point of the image moves to (200,100). why?
    Attached Images Attached Images

  11. #8
    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: QGraphicsView

    Because you didn't set the scene size and in such situation the scene adapts to the amplitude (spread) of coordinates used.

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

    Shawn (2nd June 2007)

  13. #9
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView

    I had read the Graphics View Framework for days but I am now confused with "mapping this mapping that" and still have no clear idea about my work.

    The expected diagram is like attachment "SLD", and from a xml file, I can get information like this, as showing in attachment "SLD2":
    for item E1\Q2\U1, it has 2 connectivity nodes: E1\Q2\l0, E1\Q2\l1
    for item E1\Q1\I1, it has 2 connectivity nodes: E1\Q2\l1, E1\Q2\l2
    so that I can decide that U1 is connected with I1 by connecivity node E1\Q2\l1.

    what I want to know is : using the Praphics View Framework , how can I decide each item's position ?
    Attached Images Attached Images
    Last edited by Shawn; 4th June 2007 at 14:06.

  14. #10
    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: QGraphicsView

    Position related to what? The scene? Or the parent item?

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

    Shawn (4th June 2007)

  16. #11
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView

    I just don't have an idea that how to arrange these items, the only information I have is the connectivity node.

  17. #12
    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: QGraphicsView

    It's safest to go through the scene then. Use mapToItem() or mapToScene(), depending on which one you currently need.

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

    Shawn (4th June 2007)

Similar Threads

  1. QGraphicsScene and QGraphicsView
    By rossd in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2007, 14:43
  2. QGraphicsView rendering issue
    By guilugi in forum Qt Programming
    Replies: 9
    Last Post: 6th April 2007, 09:09
  3. Simulating Video on QLabel or QGraphicsView
    By forrestfsu in forum Qt Programming
    Replies: 9
    Last Post: 21st March 2007, 10:39
  4. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04
  5. QGraphicsView and QGraphicsScene speeds
    By jnk5y in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2006, 07: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.