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. Different coordinates after setGeometry applied to QGraphicsView

Different coordinates after setGeometry applied to QGraphicsView

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 516 Views
  • 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.
  • D Offline
    D Offline
    DemensDeum
    wrote on last edited by DemensDeum
    #1

    Summary:
    Windows 11, Qt 6. I apply setGeometry to QGraphicsView which is inside of QMainWindow, but in result I get QGraphicsView in different x and y coordinates.
    I use view.setGeometry(120, 120, 320, 240); and get QGraphicsView in x 150 and y 150 coordinates, I expect it to be x 120, y 120.

    Code:

    #include <QApplication>
    #include <QMainWindow>
    #include <QGraphicsScene>
    #include <QGraphicsView>
    #include <QGraphicsVideoItem>
    #include <QMediaPlayer>
    #include <QAudioOutput>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        // Create the main window
        QMainWindow mainWindow;
        mainWindow.setWindowTitle("Video Player");
        mainWindow.setGeometry(100, 100, 800, 600);
    
        // Create a central widget to hold the QGraphicsView
        QWidget centralWidget;
        mainWindow.setCentralWidget(¢ralWidget);
    
        // Create a QGraphicsView and a QGraphicsScene
        QGraphicsView view(¢ralWidget);
        QGraphicsScene scene;
        view.setScene(&scene);
        view.setGeometry(120, 120, 320, 240);
    
        // Create a QMediaPlayer and set the media content
        QMediaPlayer mediaPlayer;
        mediaPlayer.setSource(QUrl::fromLocalFile("PM5544.mp4"));
    
        // Create a QGraphicsVideoItem and set the media player
        QGraphicsVideoItem videoItem;
        QAudioOutput audioOutput;
    
        // Add the video item to the scene
        scene.addItem(&videoItem);
    
        mediaPlayer.setAudioOutput(&audioOutput);
        mediaPlayer.setVideoOutput(&videoItem);
    
        // Play the video
        mediaPlayer.play();
    
        // Show the main window
        mainWindow.show();
    
        return app.exec();
    }
    
    

    Is that a bug, or I am doing something wrong?

    JonBJ 1 Reply Last reply
    0
    • D DemensDeum

      Summary:
      Windows 11, Qt 6. I apply setGeometry to QGraphicsView which is inside of QMainWindow, but in result I get QGraphicsView in different x and y coordinates.
      I use view.setGeometry(120, 120, 320, 240); and get QGraphicsView in x 150 and y 150 coordinates, I expect it to be x 120, y 120.

      Code:

      #include <QApplication>
      #include <QMainWindow>
      #include <QGraphicsScene>
      #include <QGraphicsView>
      #include <QGraphicsVideoItem>
      #include <QMediaPlayer>
      #include <QAudioOutput>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          // Create the main window
          QMainWindow mainWindow;
          mainWindow.setWindowTitle("Video Player");
          mainWindow.setGeometry(100, 100, 800, 600);
      
          // Create a central widget to hold the QGraphicsView
          QWidget centralWidget;
          mainWindow.setCentralWidget(¢ralWidget);
      
          // Create a QGraphicsView and a QGraphicsScene
          QGraphicsView view(¢ralWidget);
          QGraphicsScene scene;
          view.setScene(&scene);
          view.setGeometry(120, 120, 320, 240);
      
          // Create a QMediaPlayer and set the media content
          QMediaPlayer mediaPlayer;
          mediaPlayer.setSource(QUrl::fromLocalFile("PM5544.mp4"));
      
          // Create a QGraphicsVideoItem and set the media player
          QGraphicsVideoItem videoItem;
          QAudioOutput audioOutput;
      
          // Add the video item to the scene
          scene.addItem(&videoItem);
      
          mediaPlayer.setAudioOutput(&audioOutput);
          mediaPlayer.setVideoOutput(&videoItem);
      
          // Play the video
          mediaPlayer.play();
      
          // Show the main window
          mainWindow.show();
      
          return app.exec();
      }
      
      

      Is that a bug, or I am doing something wrong?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @DemensDeum said in Different coordinates after setGeometry applied to QGraphicsView:

      and get QGraphicsView in x 150 and y 150 coordinates

      Can you show in your code (e.g. a qDebug() statement) where you are seeing this, please?

      D 1 Reply Last reply
      1
      • JonBJ JonB

        @DemensDeum said in Different coordinates after setGeometry applied to QGraphicsView:

        and get QGraphicsView in x 150 and y 150 coordinates

        Can you show in your code (e.g. a qDebug() statement) where you are seeing this, please?

        D Offline
        D Offline
        DemensDeum
        wrote on last edited by
        #3

        @JonB hello, I am checking coordinates in GIMP, here is screenshot of code in first post.
        Screenshot 2023-10-24 195636.png

        And here is GIMP selection, that showing that actual coordinates is x: 150, y: 150

        Screenshot 2023-10-24 200035.png

        KenAppleby 0K 1 Reply Last reply
        0
        • D DemensDeum

          @JonB hello, I am checking coordinates in GIMP, here is screenshot of code in first post.
          Screenshot 2023-10-24 195636.png

          And here is GIMP selection, that showing that actual coordinates is x: 150, y: 150

          Screenshot 2023-10-24 200035.png

          KenAppleby 0K Offline
          KenAppleby 0K Offline
          KenAppleby 0
          wrote on last edited by
          #4

          @DemensDeum
          I think you're seeing the difference between logical and physical pixels.

          When I run your code, the following:

             // Show the main window
             mainWindow.show();
          
             qDebug() << view.geometry() << QGuiApplication::primaryScreen()->devicePixelRatio();
          

          prints out:

          QRect(120,120 320x240) 1.5
          

          and when I look at a screen dump the graphics view is offset by 180x180 physical pixels, as expected from the pixel ratio printed.

          D 1 Reply Last reply
          2
          • KenAppleby 0K KenAppleby 0

            @DemensDeum
            I think you're seeing the difference between logical and physical pixels.

            When I run your code, the following:

               // Show the main window
               mainWindow.show();
            
               qDebug() << view.geometry() << QGuiApplication::primaryScreen()->devicePixelRatio();
            

            prints out:

            QRect(120,120 320x240) 1.5
            

            and when I look at a screen dump the graphics view is offset by 180x180 physical pixels, as expected from the pixel ratio printed.

            D Offline
            D Offline
            DemensDeum
            wrote on last edited by
            #5

            @KenAppleby-0 Thank you.
            Now I am trying to understand why every app adapt dpi differently, Gimp, Firefox and Qt.

            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