void GenericHistogramView::init() { this->setMouseTracking(true); //Switch on mouse tracking (no need to press button) _qwtPlot->setTitle("Histogram"); _qwtPlot->setCanvasBackground(QColor(Qt::gray)); _qwtPlot->plotLayout()->setAlignCanvasToScales(true); _qwtPlot->setAxisTitle(QwtPlot::yLeft, "Number of specimen"); _qwtPlot->setAxisTitle(QwtPlot::xBottom, "Pixel value"); QwtLegend* legend = new QwtLegend(); legend->setItemMode(QwtLegend::CheckableItem); _qwtPlot->insertLegend(legend, QwtPlot::RightLegend); populate(); _qwtPlot->canvas()->setMouseTracking(true); if(_horizontal) _principalPicker = new HistogramPicker(QwtPlotPicker::HLineRubberBand, QwtPicker::AlwaysOn, _qwtPlot->canvas()); else _principalPicker = new HistogramPicker(QwtPlotPicker::VLineRubberBand, QwtPicker::AlwaysOn, _qwtPlot->canvas()); _principalPicker->setStateMachine(new QwtPickerDragPointMachine()); _principalPicker->setTrackerPen(QColor(Qt::white)); _principalPicker->setRubberBandPen(QColor(Qt::yellow)); _leftPicker = new HistogramPicker(_qwtPlot->canvas()); _leftPicker->setStateMachine(new QwtPickerDragPointMachine()); _rightPicker = new HistogramPicker(_qwtPlot->canvas()); _rightPicker->setStateMachine(new QwtPickerDragPointMachine()); _rightPicker->setRubberBand(QwtPlotPicker::VLineRubberBand); _rightPicker->setRubberBandPen(QColor(Qt::yellow)); _rightPicker->setMousePattern(QwtPicker::MouseSelect1, Qt::RightButton); connect(_qwtPlot, SIGNAL(legendChecked(QwtPlotItem*, bool)), this, SLOT(showItem(QwtPlotItem*, bool))); connect(_rightPicker, SIGNAL(selected(const QPointF&)), this, SLOT(rightClick(const QPointF&))); connect(_leftPicker, SIGNAL(selected(const QPointF&)), this, SLOT(leftClick(const QPointF&))); connect(_principalPicker, SIGNAL(moved(const QPointF&)), this, SLOT(move(const QPointF&))); _qwtPlot->replot(); // creating the legend items QwtPlotItemList items = _qwtPlot->itemList(QwtPlotItem::Rtti_PlotHistogram); for(int i = 0; i < items.size(); i++) { QwtLegendItem* legendItem = qobject_cast<QwtLegendItem*>(legend->find(items[i])); if(legendItem) legendItem->setChecked(true); items[i]->setVisible(true); } _qwtPlot->setAutoReplot(true); }
void LineChart::setTooltip(QString t) { tooltip = t; QwtPlot *p = plot(); if (p == NULL) return; QwtLegend *l = p->legend(); if (l == NULL) return; QwtLegendItem *legendItem = (QwtLegendItem *)l->find(this); if (legendItem != NULL) legendItem->setToolTip(tooltip); }