#include "mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ inputHistogram = new HistogramWidget; setCentralWidget(inputHistogram);}MainWindow::~MainWindow() {}
#include "histogramwidget.h"HistogramWidget::HistogramWidget(QWidget *parent) : QWidget(parent){ setMouseTracking(true); histogramMainLayout = new QHBoxLayout; histogramGroupBox = new QGroupBox(tr("Гистограмма")); histogramGroupBoxLayout = new QHBoxLayout; histogramChartLayout = new QHBoxLayout; histogramChart = new QChart; histogramChart->setTitle(tr("Визуализация данных")); histogramChart->installEventFilter(this); histogramChartView = new QChartView(histogramChart); histogramChartView->setRenderHint(QPainter::Antialiasing); histogramChartLayout->addWidget(histogramChartView); histogramGroupBoxLayout->addLayout(histogramChartLayout); histogramGroupBox->setLayout(histogramGroupBoxLayout); histogramMainLayout->addWidget(histogramGroupBox); setLayout(histogramMainLayout); sum = 0;}HistogramWidget::~HistogramWidget() {}bool HistogramWidget::eventFilter(QObject *watched, QEvent *event){ if (watched == histogramChart && event->type() == QEvent::MouseMove) { QMessageBox::information(this, "", ""); histogramChart->setTitle(QString::number(sum++)); } return false;}
bool HistogramWidget::eventFilter(QObject *watched, QEvent *event){ if (watched != histogramChart) return false; if (event->type() == QEvent::MouseMove) { QMessageBox::information(this, "", ""); histogramChart->setTitle(QString::number(sum++)); return true; } return false;}
void HistogramWidget::mouseMoveEvent(QMouseEvent *event){ histogramChart->setTitle(QString::number(sum--));}