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. Initialize QGraphicsScene
Qt 6.11 is out! See what's new in the release blog

Initialize QGraphicsScene

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 4.4k 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.
  • J Offline
    J Offline
    jk_mk
    wrote on last edited by
    #1

    Hello to all,

    I have subclassed a QGraphicsScene in order to display an image in a QGraphicsView.But I initialize the Canvas as it seems bellow in the canvas.cpp file

    @Canvas::Canvas(): QGraphicsScene(0,0,128,128)
    {
    }@

    where 128x128 is the size of the displayed image.In my mainwindow.cpp file I have created an object
    @Canvas *scene;@

    How could I set the size of the scene in my mainwindow?In this case the constructor should be like this?
    @Canvas::Canvas()
    {
    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexander
      wrote on last edited by
      #2

      Size @QGraphicsScene@ or @QGraphicsView@ ?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jk_mk
        wrote on last edited by
        #3

        I want to set the size of scene which is subclassed from QGraphicsScene if I know the width and length of this scene.
        I want to use this

        @Canvas::Canvas()
        {
        }@

        and not this to initialize the constructor of canvas
        @Canvas::Canvas(): QGraphicsScene(0,0,128,128)
        {
        }@

        where Canvas *scene;

        1 Reply Last reply
        0
        • S Offline
          S Offline
          srikanth_trulyit
          wrote on last edited by
          #4

          setSceneRect()

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jk_mk
            wrote on last edited by
            #5

            To be more specific I use a push button event and every time I press the button I run this function.But ecery time I am loading first a small image and then a bigger, everything is fine.When I am loading first a bigger image and then a smaller,then I do not take the image scaled in the hole QGraphicsView, but it is displayed in the middle of the QGraphicsView without been scaled.Could somebode help me to solve this problem?

            @void MainWindow::push_button_File(void)
            {
            ui->graphicsView_inputImage->setSceneRect(0,0,size_x,size_y);

            QPixmap tmpmap (fileName, 0, Qt::AutoColor);
            if (!pixmapItem) {
            pixmapItem = scene->addPixmap (tmpmap);
            ui->graphicsView_inputImage->setScene(scene);
            ui->graphicsView_inputImage->scale(ui->graphicsView_inputImage->width()/scene->width(),
            ui->graphicsView_inputImage ->height()/scene->height());
            } else {
            pixmapItem->setPixmap(tmpmap);

            } @

            }

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thisisbhaskar
              wrote on last edited by
              #6

              @Canvas::Canvas(int x, int y, int width, int height) : QGraphicsScene(0,0,128,128)
              {

              }@

              And set the screen to the view with

              @Canvas *scene;
              view->setScene(scene);
              @

              But I wonder whey do you want to create a class Canvas. You can directly create QGraphicsScene with what ever size you want and directly set it to QGraphicsView.

              @ QGraphcisView view;
              view->setScene(new QGraphicsScene(0,0,128.128); @

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jk_mk
                wrote on last edited by
                #7

                I have created canvas to insert a mouse press event.I have managed to get some results but they are not totaly right. Have a look at my previous post in the same topic

                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