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. How can I place a qlabel over qwidget placed in a window container?
Forum Update on Monday, May 27th 2025

How can I place a qlabel over qwidget placed in a window container?

Scheduled Pinned Locked Moved Solved General and Desktop
qlabelqwidgetwindow
6 Posts 2 Posters 1.9k 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.
  • N Offline
    N Offline
    new.qt_user-2022
    wrote on last edited by
    #1

    Hello all,

    I have a widget in which I am displaying some graph data (3D scatter plot). I display as it so:

    QHBoxLayout* const layout = new QHBoxLayout(ui->graph_display_widget);
    layout ->setMargin(0);
    layout ->addWidget(QWidget::createWindowContainer(&graph, this));
    

    This is done in the main window constructor. 'graph_display_widget' is created in the UI editor inside of a frame.

    It displays well, however I would like to place a legend over the display widget. So in the UI editor, I created a qlabel 'legend' to the dimensions I want and drag it over the graph_display_widget, and in code I do:

    QPixmap legend_pix (":/images/legend.png");
    ui->legend->setPixmap(legend_pix);
    

    The image loads correctly when not placed over the graph_display_widget in the UI editor, but when I try and place it over the graph_display_widget, the graph_display_widget comes out on top instead. Not matter what I do, graph_display_widget is always on top.

    I've tried nesting the qlabel in another frame, widget, and the other containers and placing them over graph_display_widget, but graph_display_widget will always display on top. I've tried moving graph_display_widget to the bottom and the other widgets to the top using the context menu, I even tried:

    ui->graph_display_widget->lower();
    ui->legend->raise();
    

    Same result.

    Any help would be greatly appreciated!

    JKSHJ 1 Reply Last reply
    0
    • N new.qt_user-2022

      Hello all,

      I have a widget in which I am displaying some graph data (3D scatter plot). I display as it so:

      QHBoxLayout* const layout = new QHBoxLayout(ui->graph_display_widget);
      layout ->setMargin(0);
      layout ->addWidget(QWidget::createWindowContainer(&graph, this));
      

      This is done in the main window constructor. 'graph_display_widget' is created in the UI editor inside of a frame.

      It displays well, however I would like to place a legend over the display widget. So in the UI editor, I created a qlabel 'legend' to the dimensions I want and drag it over the graph_display_widget, and in code I do:

      QPixmap legend_pix (":/images/legend.png");
      ui->legend->setPixmap(legend_pix);
      

      The image loads correctly when not placed over the graph_display_widget in the UI editor, but when I try and place it over the graph_display_widget, the graph_display_widget comes out on top instead. Not matter what I do, graph_display_widget is always on top.

      I've tried nesting the qlabel in another frame, widget, and the other containers and placing them over graph_display_widget, but graph_display_widget will always display on top. I've tried moving graph_display_widget to the bottom and the other widgets to the top using the context menu, I even tried:

      ui->graph_display_widget->lower();
      ui->legend->raise();
      

      Same result.

      Any help would be greatly appreciated!

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      @new-qt_user-2022 Unfortunately, this is a known limitation (see https://doc.qt.io/qt-5/qwidget.html#createWindowContainer ): "The embedded window will stack on top of the widget hierarchy as an opaque box. The stacking order of multiple overlapping window container instances is undefined."

      So, it is currently not possible to render a widget on top of an embedded window.

      EDIT: From your other posts, it sounds like you are using the Qt Data Visualization module? Perhaps you can implement the scatter graph and legend in QML, then put it in a QQuickWidget. See https://doc.qt.io/qt-5/qtdatavisualization-qmllegend-example.html -- Just replace the ColumnLayout + LegendItems with an Image

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      N 1 Reply Last reply
      2
      • JKSHJ JKSH

        @new-qt_user-2022 Unfortunately, this is a known limitation (see https://doc.qt.io/qt-5/qwidget.html#createWindowContainer ): "The embedded window will stack on top of the widget hierarchy as an opaque box. The stacking order of multiple overlapping window container instances is undefined."

        So, it is currently not possible to render a widget on top of an embedded window.

        EDIT: From your other posts, it sounds like you are using the Qt Data Visualization module? Perhaps you can implement the scatter graph and legend in QML, then put it in a QQuickWidget. See https://doc.qt.io/qt-5/qtdatavisualization-qmllegend-example.html -- Just replace the ColumnLayout + LegendItems with an Image

        N Offline
        N Offline
        new.qt_user-2022
        wrote on last edited by
        #3

        @JKSH I see, thank you for that. I will check out the example you provided.

        I have never used QML and have done things using purely with C++. Yes I was using the data visualization module and had everything pretty much done (display of two custom meshes, custom mesh for data points, etc).

        How difficult would it be to convert the code? Or instead of a window container, is there a way to display the visualization graph in a graphics view widget or other widget where it is possible to stack a label over it as I described?

        Thank you again!

        JKSHJ 1 Reply Last reply
        0
        • N new.qt_user-2022

          @JKSH I see, thank you for that. I will check out the example you provided.

          I have never used QML and have done things using purely with C++. Yes I was using the data visualization module and had everything pretty much done (display of two custom meshes, custom mesh for data points, etc).

          How difficult would it be to convert the code? Or instead of a window container, is there a way to display the visualization graph in a graphics view widget or other widget where it is possible to stack a label over it as I described?

          Thank you again!

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @new-qt_user-2022 said in How can I place a qlabel over qwidget placed in a window container?:

          How difficult would it be to convert the code?

          I'm not sure, sorry; it partly depends on how complex your C++ code is.

          Or instead of a window container, is there a way to display the visualization graph in a graphics view widget or other widget where it is possible to stack a label over it as I described?

          The C++ API for Qt Data Visualization is based on QWindow. No matter what widget you use, you'd need QWidget::createWindowContainer() to embed a QWindow in any widget.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          N 1 Reply Last reply
          1
          • JKSHJ JKSH

            @new-qt_user-2022 said in How can I place a qlabel over qwidget placed in a window container?:

            How difficult would it be to convert the code?

            I'm not sure, sorry; it partly depends on how complex your C++ code is.

            Or instead of a window container, is there a way to display the visualization graph in a graphics view widget or other widget where it is possible to stack a label over it as I described?

            The C++ API for Qt Data Visualization is based on QWindow. No matter what widget you use, you'd need QWidget::createWindowContainer() to embed a QWindow in any widget.

            N Offline
            N Offline
            new.qt_user-2022
            wrote on last edited by
            #5

            @JKSH Indeed, I found this in the documentation:

            "The call to QWidget::createWindowContainer is required, as all data visualization graph classes (Q3DBars, Q3DScatter, and Q3DSurface) inherit QWindow. Any class inheriting QWindow cannot be used as a widget any other way."

            --Scatter Example

            ...bummer.

            As for converting C++ to QML, according to the documentation, it should be straight forward. There is almost an equivalent QML object for every C++ object. I'm hoping I can just copy my Q3DScatter graph object to the QML equivalent and hit display or something.

            Gonna spend the week watching some QML YouTube videos in the meantime.

            Thanks again!

            JKSHJ 1 Reply Last reply
            1
            • N new.qt_user-2022

              @JKSH Indeed, I found this in the documentation:

              "The call to QWidget::createWindowContainer is required, as all data visualization graph classes (Q3DBars, Q3DScatter, and Q3DSurface) inherit QWindow. Any class inheriting QWindow cannot be used as a widget any other way."

              --Scatter Example

              ...bummer.

              As for converting C++ to QML, according to the documentation, it should be straight forward. There is almost an equivalent QML object for every C++ object. I'm hoping I can just copy my Q3DScatter graph object to the QML equivalent and hit display or something.

              Gonna spend the week watching some QML YouTube videos in the meantime.

              Thanks again!

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              @new-qt_user-2022 All the best! Feel free to post new questions if you'd like further help.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              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