Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QgraphicsScene problem
Forum Updated to NodeBB v4.3 + New Features

QgraphicsScene problem

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amritmishra
    wrote on last edited by
    #1

    I have trouble using the QgraphicsScene in Qt.

    When I am initializing the QGraphicsScene in the main.cpp i am able to use that. But when I am try to add that to an Widget & then add that to the main window its not working, I am not able to view anything. What is the problem?

    Amrit Mishra
    Software Developer
    amritmishra@vimukti.com

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Darryl DSouza
      wrote on last edited by
      #2

      Could you please post your code?

      Darryl D'Souza

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zgulser
        wrote on last edited by
        #3

        You probably have no QGraphicsView for the scene. Try to create a view(it's obvious it should be custom and inherit QGraphicsView class) and then type something like;

        @
        yourView->addScene(yourScene)
        @

        Then add some items into the scene to check if it's working or not.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          amritmishra
          wrote on last edited by
          #4

          i am using
          @ QGraphicsScene scene;
          scene.setSceneRect(-300, -300, 600, 600);

          scene.setItemIndexMethod(QGraphicsScene::NoIndex);
          

          QGraphicsView view(&scene);
          view.setRenderHint(QPainter::Antialiasing);
          view.setBackgroundBrush(QPixmap(IMG_BACKGROUND));

          view.setCacheMode(QGraphicsView::CacheBackground);
          view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
          view.setDragMode(QGraphicsView::ScrollHandDrag);

          view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
          view.resize(1000,800);
          view.show();

          QPixmap pm( IMG_BACKGROUND );
          field.setBackgroundBrush( pm );@
          

          inside the widget. And when I am calling the widget in the main window. The widget space is created but so QGraphicsScene is coming.

          Amrit Mishra
          Software Developer
          amritmishra@vimukti.com

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zgulser
            wrote on last edited by
            #5

            Did you set the parent of the view?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              amritmishra
              wrote on last edited by
              #6

              how to do that???
              I am only using this much.

              Amrit Mishra
              Software Developer
              amritmishra@vimukti.com

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                zgulser
                wrote on last edited by
                #7

                view->setParent(this)

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  amritmishra
                  wrote on last edited by
                  #8

                  thanks it solved my problem :)

                  Amrit Mishra
                  Software Developer
                  amritmishra@vimukti.com

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    [quote author="zgulser" date="1297759295"]view->setParent(this)[/quote]

                    Better set the parent in the constructor call:

                    @
                    QGraphicsView view(&scene, parentPointer);
                    // parentPointer could be this (if it's QObject based)
                    // or any other QObject that makes sense for your app
                    @

                    All QObject based classes take a parent pointer as an optional argument.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved