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. Is it possible to use QGraphicsLayout in an application with a QMainWindow?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to use QGraphicsLayout in an application with a QMainWindow?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.1k Views 3 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.
  • B Offline
    B Offline
    barrian
    wrote on last edited by
    #1

    What I was hoping to do was have a standard QMainWindow class with menus, toolbar, plus various widgets in a layout, one of which would be a graphics view showing a graphics widget that contained a graphics layout. But whenever I put the graphics view into a main window nothing gets displayed.

    As a test I took the working code provided in the Qt Basic Graphics Layouts Example, created a QMainWindow class in main, and moved the QGraphicsScene, Window and QGraphicsView creation to the main window class.

    I tested the main window class on its own, and widgets like a line edit show up fine. But the code below no longer works when in the main window class.

    QGraphicsScene scene;
    
    Window *window = new Window;
    scene.addItem(window);
    QGraphicsView view(&scene);
    view.resize(600, 600);
    view.show();
    

    I just get a blank area. If don't add the Window widget, but instead, for example, draw an ellipse that is visible. If I add a plain QGraphicsWidget with a background colour that is also visible. It is just when things are inside a layout on a graphics widget that I get nothing. I've been searching for answers, digging into the documentation and even looking through the Qt source to see if I can figure out if what I am trying to do is even possible, but without any luck.

    K 1 Reply Last reply
    0
    • B barrian

      What I was hoping to do was have a standard QMainWindow class with menus, toolbar, plus various widgets in a layout, one of which would be a graphics view showing a graphics widget that contained a graphics layout. But whenever I put the graphics view into a main window nothing gets displayed.

      As a test I took the working code provided in the Qt Basic Graphics Layouts Example, created a QMainWindow class in main, and moved the QGraphicsScene, Window and QGraphicsView creation to the main window class.

      I tested the main window class on its own, and widgets like a line edit show up fine. But the code below no longer works when in the main window class.

      QGraphicsScene scene;
      
      Window *window = new Window;
      scene.addItem(window);
      QGraphicsView view(&scene);
      view.resize(600, 600);
      view.show();
      

      I just get a blank area. If don't add the Window widget, but instead, for example, draw an ellipse that is visible. If I add a plain QGraphicsWidget with a background colour that is also visible. It is just when things are inside a layout on a graphics widget that I get nothing. I've been searching for answers, digging into the documentation and even looking through the Qt source to see if I can figure out if what I am trying to do is even possible, but without any luck.

      K Offline
      K Offline
      kenchan
      wrote on last edited by kenchan
      #2

      @barrian Why are you adding that Window to the scene as an item?
      Normally you add the QGraphicsView to the Window, the the scene to the view, then the graphics item to the scene.
      Then the items get displayed by the scene in the view on the window. Which might be in a layout on the main window or something. That much is not clear from your code snippet though.

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Did you try with
        http://doc.qt.io/qt-5/qgraphicsproxywidget.html#details

        I have not tried with complete mainwindow, though. but why not.

        B 1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          Did you try with
          http://doc.qt.io/qt-5/qgraphicsproxywidget.html#details

          I have not tried with complete mainwindow, though. but why not.

          B Offline
          B Offline
          barrian
          wrote on last edited by
          #4

          @kenchan Window is a QGraphicsWidget, so it should go into the scene. I am modifying the code from Basic Graphics Layouts Example. So it is a view showing a scene containing a graphics widget containing a variety of layouts. Once the view is inside a main window nothing is displayed on the screen. If there is no graphics layout inside the graphics widget then everything displays, but I have to do the layout myself.

          @mrjj I was trying to avoid using standard QWidgets inside the graphics scene due to the performance impact.

          mrjjM 1 Reply Last reply
          0
          • B barrian

            @kenchan Window is a QGraphicsWidget, so it should go into the scene. I am modifying the code from Basic Graphics Layouts Example. So it is a view showing a scene containing a graphics widget containing a variety of layouts. Once the view is inside a main window nothing is displayed on the screen. If there is no graphics layout inside the graphics widget then everything displays, but I have to do the layout myself.

            @mrjj I was trying to avoid using standard QWidgets inside the graphics scene due to the performance impact.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @barrian
            Hi
            I read it reverse then :)

            Why do you want to use QGraphicsLayout when you can just use the normal layouts?

            B 1 Reply Last reply
            0
            • mrjjM mrjj

              @barrian
              Hi
              I read it reverse then :)

              Why do you want to use QGraphicsLayout when you can just use the normal layouts?

              B Offline
              B Offline
              barrian
              wrote on last edited by
              #6

              @mrjj I have a scene with items I want to lay out, and I want to have the view of that scene in a layout. Something like the Qt Diagram Scene Example, but with a layout inside the scene as well.

              It has been pointed out to me that in my haste to modify the Basic Graphics Layouts Example I left everything allocated on the stack. Heap allocation solved my problem in modifying the example. From that working modified example I can figure out where I went wrong with my own application, where I was already using heap allocation for everything, but must have been doing something else wrong.

              1 Reply Last reply
              1

              • Login

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