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. Why is the clicked() signal for the QPieSlice not emitted?
Forum Updated to NodeBB v4.3 + New Features

Why is the clicked() signal for the QPieSlice not emitted?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 3.4k 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.
  • C Offline
    C Offline
    Cheery
    wrote on last edited by
    #1

    I'm using Qt charts module to draw a Nested Donuts chart just like the example in Qt Charts.
    alt text
    And I want every components (QPieSlice) response to the mouse event, the hovered() signals work well, however, the clicked() signals only work for the QpieSlices in the last added QPieSerie. It seems other QpieSlices do not emit the signals, since if I explicitly call the clicked() function, the slot response correctly. This piece of code shows the issue

    Widget::Widget(QWidget *parent): QWidget(parent){
        QChartView *chartView = new QChartView;
        QChart *chart = chartView->chart();
    
        for (int i = 0; i < donutCount; i++) {
        QPieSeries *donut = new QPieSeries;
        donut->setHoleSize(minSize + i * (maxSize - minSize) / donutCount);
        donut->setPieSize(minSize + (i + 1) * (maxSize - minSize) / donutCount);
        int sliceCount = 3 + qrand() % 3;
        for (int j = 0; j < sliceCount; j++) {
            qreal value = 100 + qrand() % 100;
            QPieSlice *slice = new QPieSlice(QString("%1").arg(value), value);
            slice->setLabelVisible(true);
            slice->setLabelColor(Qt::white);
            slice->setLabelPosition(QPieSlice::LabelInsideTangential);
            connect(slice, SIGNAL(hovered(bool)), this, SLOT(explodeSlice(bool)));
            connect(slice, SIGNAL(clicked()), this, SLOT(selected()));
            donut->append(slice);
        }
        m_donuts.append(donut);
        chartView->chart()->addSeries(donut);
    }
    
    void Widget::selected()
    {
        QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
        cout << slice->label().toStdString() << endl;
    }
    

    The press(), doubleClicked() of QPieSlice and QPieSeries::clicked(QPieSlice*) signals also have the same problem. What am I doing wrong? Can someone help me?

    1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      Can you also share the link to the bug report ?

      C Offline
      C Offline
      Cheery
      wrote on last edited by p3c0
      #6

      @SGaist Sure. QTBUG-56037 and it has already been fixed.

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

        I get the same behaviour.
        You should probably report it to https://bugreports.qt.io saying that to test it they just have to add connect(slice,&QPieSlice::clicked,[]()->void{qDebug("clicked");}); before connect(slice, SIGNAL(hovered(bool)), this, SLOT(explodeSlice(bool))); in the nested donuts example

        "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

        C 1 Reply Last reply
        3
        • VRoninV VRonin

          I get the same behaviour.
          You should probably report it to https://bugreports.qt.io saying that to test it they just have to add connect(slice,&QPieSlice::clicked,[]()->void{qDebug("clicked");}); before connect(slice, SIGNAL(hovered(bool)), this, SLOT(explodeSlice(bool))); in the nested donuts example

          C Offline
          C Offline
          Cheery
          wrote on last edited by
          #3

          @VRonin Thank you for your rely. I have reported this bug. And I wonder if there's any other way to deal with the mouse event. I try to overwrite the mousePressEvent() function, but it doesn't work. It seems that the QChartView has already accept the event. Do you know any other solution?

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

            I'm pretty sure you can still intsall an event filter on it http://doc.qt.io/qt-5/eventsandfilters.html#event-filters

            "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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Hi,

              Can you also share the link to the bug report ?

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

              C 1 Reply Last reply
              2
              • SGaistS SGaist

                Hi,

                Can you also share the link to the bug report ?

                C Offline
                C Offline
                Cheery
                wrote on last edited by p3c0
                #6

                @SGaist Sure. QTBUG-56037 and it has already been fixed.

                D 1 Reply Last reply
                3
                • C Cheery

                  @SGaist Sure. QTBUG-56037 and it has already been fixed.

                  D Offline
                  D Offline
                  Devopia53
                  wrote on last edited by
                  #7

                  @Cheery

                  Everything is my guess...

                  The cause of this bug is thought to be the QGraphicsItem::ItemIsSelectable flag when creating the items(QPieSeries, QPieSlice).

                  // line 66, in piechartitem.cpp
                  setFlag(QGraphicsItem::ItemIsSelectable);
                  
                  // line 59, in piesliceitem.cpp
                  setFlag(QGraphicsItem::ItemIsSelectable);
                  

                  The "emit pressed()" is omitted because it performs the "setSelected()" when clicking the item with the mouse(left button). Exclude last appended items (Top-most items)

                  // line 7169, in QGraphicsItem.cpp
                  void QGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
                  {
                      if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {
                  

                  If you want to perform that function with the current version(5.7), you can use some tricks. If RightButton is not needed...

                  void MyChartView::mousePressEvent(QMouseEvent *event)
                  {
                      if (event->button() == Qt::LeftButton) {
                          QMouseEvent ev(event->type(), event->localPos(), Qt::RightButton, Qt::RightButton, event->modifiers());
                  
                          QChartView::mousePressEvent(&ev);
                      }
                      else
                          QChartView::mousePressEvent(event);
                  }
                  
                  C 1 Reply Last reply
                  0
                  • D Devopia53

                    @Cheery

                    Everything is my guess...

                    The cause of this bug is thought to be the QGraphicsItem::ItemIsSelectable flag when creating the items(QPieSeries, QPieSlice).

                    // line 66, in piechartitem.cpp
                    setFlag(QGraphicsItem::ItemIsSelectable);
                    
                    // line 59, in piesliceitem.cpp
                    setFlag(QGraphicsItem::ItemIsSelectable);
                    

                    The "emit pressed()" is omitted because it performs the "setSelected()" when clicking the item with the mouse(left button). Exclude last appended items (Top-most items)

                    // line 7169, in QGraphicsItem.cpp
                    void QGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
                    {
                        if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {
                    

                    If you want to perform that function with the current version(5.7), you can use some tricks. If RightButton is not needed...

                    void MyChartView::mousePressEvent(QMouseEvent *event)
                    {
                        if (event->button() == Qt::LeftButton) {
                            QMouseEvent ev(event->type(), event->localPos(), Qt::RightButton, Qt::RightButton, event->modifiers());
                    
                            QChartView::mousePressEvent(&ev);
                        }
                        else
                            QChartView::mousePressEvent(event);
                    }
                    
                    C Offline
                    C Offline
                    Cheery
                    wrote on last edited by
                    #8

                    @Devopia53 said in Why is the clicked() signal for the QPieSlice not emitted?:

                    void MyChartView::mousePressEvent(QMouseEvent *event)
                    {
                    if (event->button() == Qt::LeftButton) {
                    QMouseEvent ev(event->type(), event->localPos(), Qt::RightButton, Qt::RightButton, event->modifiers());

                        QChartView::mousePressEvent(&ev);
                    }
                    else
                        QChartView::mousePressEvent(event);
                    

                    }

                    Thank you for your rely. This method do work well.

                    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