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 use qgraphicsitem in qtchart?
Qt 6.11 is out! See what's new in the release blog

How to use qgraphicsitem in qtchart?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 2.8k 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.
  • DaryongD Offline
    DaryongD Offline
    Daryong
    wrote on last edited by Daryong
    #1

    Hi,

    I want to display various custom shapes, image and lines in qtchart.
    QChart does not inherit from QGraphicsScene, how do I use qgraphicitem ?
    And the use coordinates of qgraphicsitem want to use the x, y coordinate system of qchart.

    thanks.

    mrjjM 1 Reply Last reply
    0
    • DaryongD Daryong

      Hi,

      I want to display various custom shapes, image and lines in qtchart.
      QChart does not inherit from QGraphicsScene, how do I use qgraphicitem ?
      And the use coordinates of qgraphicsitem want to use the x, y coordinate system of qchart.

      thanks.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Daryong
      Hi
      There is not something like
      app->chart()->scene() ?

      1 Reply Last reply
      2
      • m. selimM Offline
        m. selimM Offline
        m. selim
        wrote on last edited by m. selim
        #3

        QChart is descendant of QGraphicsWidget which in term is descendant of QGraphicsItem
        So it's meant to be placed in a QGraphicsScene within QGraphicsView::scene().

        You can use QGraphicsView to render your QChart as well as any other customized QGraphicsItem.
        You have first to subclass QGraphicsView, within the constructor, you can call the virtual method scene() .
        Which would you able add QCharts and other QGraphicsItem objects. i.e. scene()->addItem(new QChart) or scene()->addItem(new QGraphicsItem).

        And for the coordinates of QChart, I am not quite sure, but you might subclass a QGraphicsItem parent it to the QChart and override it's paint method

        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget);
        

        to draw custom shapes within the QCharts coordinate system using QPainter.

        1 Reply Last reply
        1

        • Login

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