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. Getting a QtChartView inside of a QGraphicsView

Getting a QtChartView inside of a QGraphicsView

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.9k Views 1 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.
  • M Offline
    M Offline
    MichaelH
    wrote on last edited by
    #1

    Hi,

    i have added a QGraphicsView to a .ui file.
    In the according class i make a QChartView and want to show that chart in the QGraphicsView.

    I have tried the following things, but they did not work:

    1.)
    QChartView* tmp = new QChartView(...);
    ui->graphics_view = tmp;

    2.)
    QChartView* tmp = new QChartView(...);
    QGraphicsView* graphics_view = new QGraphicsView(tmp);
    ui->graphics_view = tmp;

    The two methods do not work and i cannot really find a way to get a chartview inside of my graphics view.
    Can not be too hard to do what i want, or is it?

    1 Reply Last reply
    1
    • M Offline
      M Offline
      MichaelH
      wrote on last edited by
      #2

      i found a great answer by "eyllanesc" on stackoverflow right here:
      https://stackoverflow.com/questions/48362864/how-to-insert-qchartview-in-form-with-qt-designer

      it is possible to right click the graphics view in the ui editor and then in the menu click on promote to.
      There you can type "QChartView" in the promoted class name field and "QtCharts" in the Header File field.

      Then it is possible to go to the code and just say ui->graphics_view->setChart(&chart);

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        You are just replacing a pointer with something different. It's even surprising that it's compiling at all.

        Since QChartView is widget, use the addWidget method from the QGraphicsScene that you set on your QGraphicsView.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MichaelH
          wrote on last edited by
          #4

          @SGaist said in Getting a QtChartView inside of a QGraphicsView:

          ce QChartView

          Thanks for the answer.
          Yes i was just desperatly trying to do something..

          I have already fixed my issue, but thanks for another solution.

          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