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 to integrate a Q3DScatter graph into a Widget in a Main Window?

How to integrate a Q3DScatter graph into a Widget in a Main Window?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.3k 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.
  • R Offline
    R Offline
    Reda94
    wrote on last edited by
    #1

    I'm trying to display a Q3DScatter graph in a Main Window designed with Qt Designer so I've added a widget to the main window but I don't know how to embed the graph object in this widget. I tried to create a widget "container" programmatically and embed the graph in it and then putting the widget in a QHBoxLayout (which has been added to the main window using Qt Designer) using the following code in my main window's constructor:

    ...
    Q3DScatter *graph = new Q3DScatter();
    QWidget *container = QWidget::createWindowContainer(graph);
    ui->horizontal_layout->addWidget(container, 1);
    

    But the window appears to be empty when executing. I'd really appreciate some help.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      Code looks correct but you are not adding any series to the scatter... that's why it's empty

      Q3DScatter *graph = new Q3DScatter();
      
       QScatter3DSeries *series = new QScatter3DSeries;
          QScatterDataArray data;
          data << QVector3D(0.5f, 0.5f, 0.5f) << QVector3D(-0.3f, -0.5f, -0.4f) << QVector3D(0.0f, -0.3f, 0.2f);
          series->dataProxy()->addItems(data);
          graph->addSeries(series);
      QWidget *container = QWidget::createWindowContainer(graph,this);
      ui->horizontal_layout->addWidget(container);
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      R 1 Reply Last reply
      1
      • R Offline
        R Offline
        Reda94
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • VRoninV VRonin

          Code looks correct but you are not adding any series to the scatter... that's why it's empty

          Q3DScatter *graph = new Q3DScatter();
          
           QScatter3DSeries *series = new QScatter3DSeries;
              QScatterDataArray data;
              data << QVector3D(0.5f, 0.5f, 0.5f) << QVector3D(-0.3f, -0.5f, -0.4f) << QVector3D(0.0f, -0.3f, 0.2f);
              series->dataProxy()->addItems(data);
              graph->addSeries(series);
          QWidget *container = QWidget::createWindowContainer(graph,this);
          ui->horizontal_layout->addWidget(container);
          
          R Offline
          R Offline
          Reda94
          wrote on last edited by Reda94
          #4

          @VRonin Thanks for answering! I've tried your code but it's still not showing the graph, here's the full code of my main window constructor:

          ResultsWindow::ResultsWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::ResultsWindow)
          {
          ui->setupUi(this);
          Q3DScatter *graph = new Q3DScatter();

           QScatter3DSeries *series = new QScatter3DSeries;
           QScatterDataArray data;
           data << QVector3D(0.5f, 0.5f, 0.5f) << QVector3D(-0.3f, -0.5f, -0.4f) << QVector3D(0.0f, -0.3f, 0.2f);
           series->dataProxy()->addItems(data);
           graph->addSeries(series);
          QWidget *container = QWidget::createWindowContainer(graph,this);
          ui->h_graph->addWidget(container);
          

          }

          The layout which is supposed to contain the graph appears empty.

          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