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. QLegendMarker signal/slot connect not working
Forum Updated to NodeBB v4.3 + New Features

QLegendMarker signal/slot connect not working

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 373 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.
  • D Offline
    D Offline
    diego-qt
    wrote on last edited by diego-qt
    #1

    Hello, I am trying to make a chart where the user can hide and show the available line series by clicking the respective legend marker, like this:

        QList<QLineSeries*> lineSeries;
        for(int i = 0; i < nbCharts; i++)
        {
            QLineSeries *series = new QLineSeries;
            lineSeries.append(series);
            chart->addSeries(series);
            series->attachAxis(axisX);
            series->attachAxis(axisY);
            QLegendMarker *marker = chart->legend()->markers(series)[0];
            marker->setLabel(QString::number(i));
            connect(marker, SIGNAL(clicked()), this, SLOT(markerClicked()));
            connect(marker, SIGNAL(hovered(bool)), this, SLOT(markerHovered(bool)));
        }
    

    However, this doesn't seem to work and I don't understand why. I have the two slot functions in the public slots section in header file, I have no error notifications regarding the connect when debugging and when I put qDebug << before the connect lines, the debugger gives me true.

    I tried the code in the example in https://doc.qt.io/archives/qt-5.7/qtcharts-legendmarkers-example.html like this:

        for(int i = 0; i < nbCharts; i++)
        {
            QLineSeries *series = new QLineSeries;
            lineSeries.append(series);
            chart->addSeries(series);
            series->attachAxis(axisX);
            series->attachAxis(axisY);
            QLegendMarker *marker = chart->legend()->markers(series)[0];
            marker->setLabel(QString::number(i));
        }
        const auto markers = chart->legend()->markers();
        for (QLegendMarker *marker : markers) {
            connect(marker, SIGNAL(clicked()), this, SLOT(markerClicked()));
            connect(marker, SIGNAL(hovered(bool)), this, SLOT(markerHovered(bool)));
        }
    

    but it hasn't worked either. Any ideas why this doesn't work?

    Edit: the chart works fine. I am able to add points to the series and print them in the chart and do other things. It's just the connect that doesn't seem to work.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      diego-qt
      wrote on last edited by diego-qt
      #2

      I made a QPushButton that would simulate clicking the QLegendMarker with a connect:

          QPushButton *butt = new QPushButton("activate marker0");
          QLegendMarker *marker = chart->legend()->markers()[0];
          connect(butt, &QPushButton::clicked, marker, &QLegendMarker::clicked);
          butt->show();
      

      This actually worked and I can see the first line series disappear and reappear with the click of the button.
      I realized that I did override the mousePressEvent, mouseMoveEvent and mouseReleaseEvent functions of the class (which inherits from QChartView), so could this mean that I can't override these functions AND use the clicked and hovered signals from QLegendMarker?

      Christian EhrlicherC 1 Reply Last reply
      0
      • D diego-qt

        I made a QPushButton that would simulate clicking the QLegendMarker with a connect:

            QPushButton *butt = new QPushButton("activate marker0");
            QLegendMarker *marker = chart->legend()->markers()[0];
            connect(butt, &QPushButton::clicked, marker, &QLegendMarker::clicked);
            butt->show();
        

        This actually worked and I can see the first line series disappear and reappear with the click of the button.
        I realized that I did override the mousePressEvent, mouseMoveEvent and mouseReleaseEvent functions of the class (which inherits from QChartView), so could this mean that I can't override these functions AND use the clicked and hovered signals from QLegendMarker?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @diego-qt said in QLegendMarker signal/slot connect not working:

        so could this mean that I can't override these functions AND use the clicked and hovered signals from QLegendMarker?

        You can but when you override a function you should call the base class when you want it's functionality.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • D Offline
          D Offline
          diego-qt
          wrote on last edited by
          #4

          Yes, I added QChartView::mousePressEvent(event) (and the other two) at the end of the respective overriden functions and it works now.

          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