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 do I inherit QChart from the main window?
Forum Updated to NodeBB v4.3 + New Features

How do I inherit QChart from the main window?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 245 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.
  • L Offline
    L Offline
    LISP
    wrote on last edited by LISP
    #1

    How do I inherit QChart from the main window?

    mainwindow.h

    class MainWindow : public QMainWindow {
    public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    }
    

    mainwindow.cpp

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {...}
    

    I want to access QChart's protected member so I want to inherit QChart from main window.
    I want to deal with QChart's viewportEvent, mousePressEvent, mouseMoveEvent.

    I made the correction as below.

    mainwindow.h

    class MainWindow : public QMainWindow, public QChart {
    public:
    MainWindow(QWidget *parent = nullptr, QChart *qc = nullptr);
    ~MainWindow();
    

    mainwindow.cpp

    MainWindow::MainWindow(QWidget *parent, QChart *qc) : QMainWindow(parent), QChart(qc), ui(new 
    Ui::MainWindow) {...}
    

    But, I get an error.
    "mainwindow parameter error" and Modifying parent->connect() and How can I access the parent in a function declared inside mainwidow?
    For example, if I use setWindowTitle("text") , I cannot use parent->setWindowTitle().

    Thank you for reading my poor English.

    J.HilkJ 1 Reply Last reply
    0
    • L LISP

      How do I inherit QChart from the main window?

      mainwindow.h

      class MainWindow : public QMainWindow {
      public:
      MainWindow(QWidget *parent = nullptr);
      ~MainWindow();
      }
      

      mainwindow.cpp

      MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {...}
      

      I want to access QChart's protected member so I want to inherit QChart from main window.
      I want to deal with QChart's viewportEvent, mousePressEvent, mouseMoveEvent.

      I made the correction as below.

      mainwindow.h

      class MainWindow : public QMainWindow, public QChart {
      public:
      MainWindow(QWidget *parent = nullptr, QChart *qc = nullptr);
      ~MainWindow();
      

      mainwindow.cpp

      MainWindow::MainWindow(QWidget *parent, QChart *qc) : QMainWindow(parent), QChart(qc), ui(new 
      Ui::MainWindow) {...}
      

      But, I get an error.
      "mainwindow parameter error" and Modifying parent->connect() and How can I access the parent in a function declared inside mainwidow?
      For example, if I use setWindowTitle("text") , I cannot use parent->setWindowTitle().

      Thank you for reading my poor English.

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

      @LISP you can't do that,

      with the current implementation of the Q_OBJECT magic, you can not inherit multiple times from QObject.

      If you really need to access protected stuff from QCharts, make an interface class around it and define getters and setters


      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
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved