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. The correct way to use the “HorizontalStackedBarChart” as a clase

The correct way to use the “HorizontalStackedBarChart” as a clase

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 230 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.
  • J Offline
    J Offline
    Josz
    wrote on last edited by Josz
    #1

    Hello,
    After testing the cited example https://doc.qt.io/qt-5.11/qtcharts-horizontalstackedbarchart-main-cpp.html , I tried to use it like a class, to freely insert into a MainWindow.
    The problem was that I couldn’t use the four last lines for create the chart:
    QMainWindow window;
    window.setCentralWidget(chartView);
    window.resize(420, 300);
    window.show();

    So I returned a pointer from chartView in mybars.cpp through QChartView *myBars::returnChart()
    mybars.cpp: https://pastebin.com/K4EkVz5R
    And in mainWindow.cpp I did setCentralWidget(bars->returnChart());

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent), ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        setFixedSize(1024,768);
        bars = new myBars(this);
        bars->show();
        setCentralWidget(bars->returnChart());
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    That works, but, I wonder me, Is that the right method to use it as clase? Is there a better method to insert the chart into main window?

    Thanks in advance

    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