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. Detecting QCandlestickSet in a QList<QGraphicsItem *>

Detecting QCandlestickSet in a QList<QGraphicsItem *>

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 841 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.
  • M Offline
    M Offline
    MiC78
    wrote on last edited by VRonin
    #1

    Hi everyone,

    I am really having troubles to detect the QCandelstickSet elements after calling the next sentence:
    itemList = scene->items(rect, Qt::IntersectsItemShape, Qt::DescendingOrder);

    Of course, the QCandlestickSet elements are drawn in a Qchart in a QChartView, which has its corresponding scene.

    I tried the following but did not work:

    for (int i = 0; i < itemList.count(); ++i)
      {
        QCandlestickSet *set = dynamic_cast<QCandlestickSet*>(itemList.at(i));
        if(set)
        {
         ...
        }
      }
    

    I was reading the Qt documentation but I think I am missing something. It says that it must be through the const int QGraphicsItem::UserType
    The lowest permitted type value for custom items (subclasses of QGraphicsItem or any of the standard items). This value is used in conjunction with a reimplementation of QGraphicsItem::type() and declaring a Type enum value. Example:

      class CustomItem : public QGraphicsItem
      {
      public:
         enum { Type = UserType + 1 };
    
         int type() const
         {
             // Enable the use of qgraphicsitem_cast with this item.
             return Type;
         }
         ...
      };
    

    Does that mean that I have to create my own QCandlestickSet class derived from QGraphicsItem?

    If someone knows how to do it, I would really appreciate an example.

    Thank you.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      QCandlestickSet does not inherit QGraphicsItem so there's no way your cast can have success.

      The cast could work with CandlestickChartItem but it's a private class: https://code.woboq.org/qt5/qtcharts/src/charts/candlestickchart/candlestickchartitem_p.h.html

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • AndeolA Offline
        AndeolA Offline
        Andeol
        wrote on last edited by
        #3

        Does that mean that I have to create my own QCandlestickSet class derived from QGraphicsItem?

        I think so. Not sure, since I don't really understand what you are trying to do. scene->items() will give you a list of items. Nothing else is going to be in this list.

        This is the first time I hear about candleStickSet, so I'm not sure, but can't you do something like this?

        class myCandleStickItem: public QGraphicsItem{
        public:
        myCandleStickItem(QWidget *parent = Q_NULLPTR) ;
        QCandlestickSet getcandlestickSet() {return candlestickSet ;}
        void setCandleStickSet( QCandlestickSet newone) { candlestickSet  = newone ;}
        
        private: 
        QCandlestickSet candlestickSet;
        }
        

        Developer for R++ : https://rplusplus.com/

        M 1 Reply Last reply
        0
        • AndeolA Andeol

          Does that mean that I have to create my own QCandlestickSet class derived from QGraphicsItem?

          I think so. Not sure, since I don't really understand what you are trying to do. scene->items() will give you a list of items. Nothing else is going to be in this list.

          This is the first time I hear about candleStickSet, so I'm not sure, but can't you do something like this?

          class myCandleStickItem: public QGraphicsItem{
          public:
          myCandleStickItem(QWidget *parent = Q_NULLPTR) ;
          QCandlestickSet getcandlestickSet() {return candlestickSet ;}
          void setCandleStickSet( QCandlestickSet newone) { candlestickSet  = newone ;}
          
          private: 
          QCandlestickSet candlestickSet;
          }
          
          M Offline
          M Offline
          MiC78
          wrote on last edited by
          #4

          @Andeol
          Hi,
          Maybe I should have started saying that I have a QCandlestickSeries *series where I store financial data. Each single day in the series is stored in its corresponding QCandelstickSets *set. The series is added to a QChart chart and this one presented in a QChartView view.

          So far everything works since the date is drawn when I press the button. I even reimplemented the QChartView class to have my own zoom command. And that works also. This is the part of the reimplemented class with respect to the zoom:

          void ChartView::keyPressEvent(QKeyEvent *event)
          {
          QRectF rect = chart()->plotArea();
          qreal adjustment = rect.width() / 2;

          switch (event->key())
          {
          case Qt::Key_Up:
          {

              //rect.setX(chart()->plotArea().x() + adjustment);
              rect.adjust(adjustment, 0, 0, 0);
              chart()->zoomIn(rect);
            }
            break;
          

          case Qt::Key_Down:
          .
          .
          .

          As you can see, the zoom is only in the X axis.
          I would like to zoom the Y axis as well, but in such a way that it takes into account the maximum value of the different sets (QCandlestickSet) that fall inside the x-zoomed area. That is to say, I would like an autoscale in the Y axis to watch the sets as big as possible.

          To do that, I was thinking on something like:

          QGraphicsScene *scene = chart()->scene();
          QList<QGraphicsItem *> itemList;
          itemList = scene->items(rect, Qt::IntersectsItemShape, Qt::DescendingOrder);

          But this is not working, as you guys said before.

          Thank you very much for your help,

          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