Results 1 to 4 of 4

Thread: QGraphicsscene and QGraphicsview

  1. #1
    Join Date
    Jul 2015
    Posts
    21
    Thanks
    10
    Qt products
    Qt5
    Platforms
    Windows

    Smile QGraphicsscene and QGraphicsview

    Hey guys,
    my Code:
    Qt Code:
    1. #include "../header/analyse.h"
    2. #include "ui_analyse.h"
    3. #include <QDebug>
    4.  
    5. Analyse::Analyse(QWidget *parent) :
    6. QWidget(parent),
    7. ui(new Ui::Analyse)
    8. {
    9.  
    10. ui->setupUi(this);
    11.  
    12. scene = new QGraphicsScene();
    13. this->ui->graphicsView->setScene(scene);
    14. this->ui->graphicsView->setRenderHint(QPainter::Antialiasing);
    15.  
    16. }
    17.  
    18. Analyse::~Analyse()
    19. {
    20. delete ui;
    21. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef ANALYSE_H
    2. #define ANALYSE_H
    3.  
    4. #include <QWidget>
    5. #include <QPushButton>
    6. #include <QGraphicsLineItem>
    7. #include <QStringList>
    8. namespace Ui {
    9. class Analyse;
    10. }
    11.  
    12. class Analyse : public QWidget
    13. {
    14. Q_OBJECT
    15. public:
    16. explicit Analyse(QWidget *parent = 0);
    17. ~Analyse();
    18. private:
    19. Ui::Analyse *ui;
    20. };
    21. #endif // ANALYSE_H
    To copy to clipboard, switch view to plain text mode 
    The user can add moveable Items to the scene. I want that you can only move Items through the right border. I got two problems:
    The borders one the left, top and bottom site. If you try to move an item through this borders it stops.(colide)
    If you move items to the right border of the scene scroll bars should appear. and the scene should extend.
    A scene like this :
    ---------------------------------
    |
    |
    | ->->->->->->->->->->->->->->->->
    |
    |___________________
    I tried a lot of things and looked around. I would be happy if someone can help me.
    Greets
    Last edited by ReasyEasyPeasy; 4th October 2015 at 23:00.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsscene and QGraphicsview

    First point - this is a memory leak. Create it with "this" as a parent so it is deleted when your Analyse widget instance goes out of scope.

    scene = new QGraphicsScene();
    It would be easier to accomplish what you want is you make your scene bigger than your graphics view, and set the view's sceneRect() to the size you need. As the user drags an item to the right, you can enlarge the scene rect as needed.

  3. #3
    Join Date
    Jul 2015
    Posts
    21
    Thanks
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsscene and QGraphicsview

    Hey thanks for this fast answer!
    the size of my QGraphicsview get changed if you change the window size. How can i deal with this?
    And if I use your settings you can still move an item through the border. Is there an easy way to fix this?
    Greets

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsscene and QGraphicsview

    You will probably have to implement a handler for QGraphicsItem::itemChange(). The example code at the doc link does almost exactly what you need in the case where the item is about to move across a forbidden boundary. Also look at the Qt "elasticnodes" example.

Similar Threads

  1. Replies: 1
    Last Post: 8th September 2012, 06:08
  2. Help with QGraphicsScene
    By justin123 in forum Newbie
    Replies: 2
    Last Post: 3rd June 2010, 01:48
  3. Too Much RAM used by QGraphicsScene
    By grabalon in forum Qt Programming
    Replies: 4
    Last Post: 6th May 2010, 16:38
  4. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 18:27
  5. Help on QGraphicsScene
    By Sandip in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 15:20

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.