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. Adding a GraphicsScene into a QLabel
Qt 6.11 is out! See what's new in the release blog

Adding a GraphicsScene into a QLabel

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 4.7k 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.
  • C Offline
    C Offline
    chrisLucr
    wrote on last edited by
    #3

    On my main.cpp i am using w.show(); with w is my MainWindow where i have put the label the scene and the central widget . I am kind of new to qt so i don t know a lot of things , is using a QWidget will make the work easier ?

    jsulmJ 1 Reply Last reply
    0
    • C chrisLucr

      On my main.cpp i am using w.show(); with w is my MainWindow where i have put the label the scene and the central widget . I am kind of new to qt so i don t know a lot of things , is using a QWidget will make the work easier ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @chrisLucr QLabel is usually used to show text and images, for QGraphicsScene I would use QWidget.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • C chrisLucr

        I have a problem displaying two labels, the label "label" is displayed with no problem ( it has some buttons adjusted Horizontally ) and the second label "label1" is not being displayed ( it contains a scene which has a view , in the scene i have a title and a picture ). This is the code i am trying to use.

        widget1 = new QWidget;
        setCentralWidget(widget1);
        
        label1 = new QLabel(widget1);
        scene = new QGraphicsScene(label1);
        vue = new QGraphicsView(scene);
        label1->move(100,100);
        
        label = new QLabel(widget1);
        layout = new QHBoxLayout(label);
        label->resize(500,100);
        

        It's my first time using QGraphicsScene/View and it is confusing me a little bit.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #5

        hi @chrisLucr and welcome

        I think you're confusing some things.

        The GraphixsView object will show/display your QGraphicsScene

        What you did was creating a Scene and a view as children of your QLabel. But that will not lead to automatic resizing of the QGraphicsView nor to an automatic show() call.

        this, for example, will create and show a QScene inside a view

        QGraphicsScene scene;
        scene.addText("Hello, world!");
        
        QGraphicsView view(&scene);
        view.show();
        

        I assume, you can simply add your QGraphicsView to a layout, no need to go the way over a Label.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        2
        • C Offline
          C Offline
          chrisLucr
          wrote on last edited by
          #6

          i have tried this ,
          but it does not work too,
          i still can t see the scene in my window, all i am seeing are the buttons i have made
          ( the picture show exactely what i am trying to do : 0_1551258173240_Untitled.png )
          ```

          widget2 = new QWidget(widget1);
              scene = new QGraphicsScene(widget2);
              vue = new QGraphicsView(scene);
          
          jsulmJ 1 Reply Last reply
          0
          • C chrisLucr

            i have tried this ,
            but it does not work too,
            i still can t see the scene in my window, all i am seeing are the buttons i have made
            ( the picture show exactely what i am trying to do : 0_1551258173240_Untitled.png )
            ```

            widget2 = new QWidget(widget1);
                scene = new QGraphicsScene(widget2);
                vue = new QGraphicsView(scene);
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #7

            @chrisLucr you still don't call show()...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chrisLucr
              wrote on last edited by
              #8

              well i have tried it and i deleted the line (view.show();) since i don t need two windows to appear but still does not work , i am trying to display the scene/view on the same window as the other labels.
              @jsulm i don t call it cause when i do two windows appear when i need only one. this is the code in my main.cpp where i am showing the window ( i think it does the job ?? )
              ```
              QApplication a(argc, argv);
              MainWindow w;
              w.show();

              return a.exec();
              
              jsulmJ 1 Reply Last reply
              0
              • C chrisLucr

                well i have tried it and i deleted the line (view.show();) since i don t need two windows to appear but still does not work , i am trying to display the scene/view on the same window as the other labels.
                @jsulm i don t call it cause when i do two windows appear when i need only one. this is the code in my main.cpp where i am showing the window ( i think it does the job ?? )
                ```
                QApplication a(argc, argv);
                MainWindow w;
                w.show();

                return a.exec();
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @chrisLucr What about giving your view a parent widget, so it is not shown in its own window?

                widget2 = new QWidget(widget1);
                scene = new QGraphicsScene();
                vue = new QGraphicsView(scene, widget2);
                widget2->show();
                vue->show();
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                3
                • C Offline
                  C Offline
                  chrisLucr
                  wrote on last edited by
                  #10

                  Thanks a lot @jsulm , it is working fine now
                  really appreciate it

                  Pablo J. RoginaP 1 Reply Last reply
                  0
                  • C chrisLucr

                    Thanks a lot @jsulm , it is working fine now
                    really appreciate it

                    Pablo J. RoginaP Offline
                    Pablo J. RoginaP Offline
                    Pablo J. Rogina
                    wrote on last edited by
                    #11

                    @chrisLucr if your issue is solved, please don't forget to mark your post as such. Thanks

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      chrisLucr
                      wrote on last edited by
                      #12

                      Thanks i did not know if it exists . it will be done

                      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