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 place a Chart created in main.cpp into a dock widget?

How to place a Chart created in main.cpp into a dock widget?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 259 Views 2 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello everyone, hope all is well! I am currently trying to promote a display a QChart created in the main.cpp file to display in a dock widget contained in my QMainWindow file. I have been trying to do this by creating a widget to host the chart and then promoting the widget to the dock in the main window, but have not quite been able to get it to display. Here is the code I have for my main.cpp file:

    QChart *chart1 = new QChart();
        chart1->addSeries(series);
        chart1->setTitle("TitleOne");
        chart1->legend()->hide();
    
        QChart *chart2 = new QChart();
        chart2->addSeries(series2);
        chart2->setTitle("Title2");
        chart2->legend()->hide();
    
        QChartView *chartView1 = new QChartView(chart1);
        QChartView *chartView2 = new QChartView(chart2);
        chartView1->setRenderHint(QPainter::Antialiasing);
        chartView2->setRenderHint(QPainter::Antialiasing);
    
    
        QChartView c1;
        QChartView c2;
        c1.setChart(chart1);
        c2.setChart(chart2);
        c1.resize(840,600);
        c2.resize(840,600);
        c1.show();
        c2.show();
    
        MainWindow w;
        w.show();
    

    Note: I tested to make sure my charts were working by creating two separate windows. The widget file and MainWindow file both contain default code. I thought that setting the charts in the main file and then finding a way to call them in the widget file would work, but I have had no luck in doing that. With that being said...

    How would I get this code to display in the dock through promoting? Or, is there a simpler way to do this, such as creating the chart in the widget file? In the end, the main thing I am asking is how do you display a chart inside a dock widget? Thank you, in advance, for your time and consideration!

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

      Hi and welcome to the forums

      The promotion feature of QCreator is mostly used for using own customs controls in UI files.
      Normally not for Qt classes and it cant really help in this case any way

      To show it a Dock in main window, simply move the code there.
      Then when creating the dock, assign the QCharts

      There seems to be no idea to create them in main.cpp ?

      ? 1 Reply Last reply
      2
      • ? A Former User

        Hello everyone, hope all is well! I am currently trying to promote a display a QChart created in the main.cpp file to display in a dock widget contained in my QMainWindow file. I have been trying to do this by creating a widget to host the chart and then promoting the widget to the dock in the main window, but have not quite been able to get it to display. Here is the code I have for my main.cpp file:

        QChart *chart1 = new QChart();
            chart1->addSeries(series);
            chart1->setTitle("TitleOne");
            chart1->legend()->hide();
        
            QChart *chart2 = new QChart();
            chart2->addSeries(series2);
            chart2->setTitle("Title2");
            chart2->legend()->hide();
        
            QChartView *chartView1 = new QChartView(chart1);
            QChartView *chartView2 = new QChartView(chart2);
            chartView1->setRenderHint(QPainter::Antialiasing);
            chartView2->setRenderHint(QPainter::Antialiasing);
        
        
            QChartView c1;
            QChartView c2;
            c1.setChart(chart1);
            c2.setChart(chart2);
            c1.resize(840,600);
            c2.resize(840,600);
            c1.show();
            c2.show();
        
            MainWindow w;
            w.show();
        

        Note: I tested to make sure my charts were working by creating two separate windows. The widget file and MainWindow file both contain default code. I thought that setting the charts in the main file and then finding a way to call them in the widget file would work, but I have had no luck in doing that. With that being said...

        How would I get this code to display in the dock through promoting? Or, is there a simpler way to do this, such as creating the chart in the widget file? In the end, the main thing I am asking is how do you display a chart inside a dock widget? Thank you, in advance, for your time and consideration!

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @WesLow

        In addition to what @mrjj said, you can create an empty dock widget in Designer. Then go to your code, access the widget and add your QChart page to it.
        There is no need for widget promotion.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • mrjjM mrjj

          Hi and welcome to the forums

          The promotion feature of QCreator is mostly used for using own customs controls in UI files.
          Normally not for Qt classes and it cant really help in this case any way

          To show it a Dock in main window, simply move the code there.
          Then when creating the dock, assign the QCharts

          There seems to be no idea to create them in main.cpp ?

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @mrjj Thank you very much for your help! This worked!

          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