在悬停事件上,我希望在QChart的相应栏上方插入图形。 QChart上的QBarSeries中有多个QBarSet,我无法将图形放置在正确的条形上方。能够在悬停事件上在QChart上显示图形并将其正确垂直放置(y轴),但是无法获得正确的水平位置(x轴)。我的最佳尝试(下面的选项2)将图形放置在正确的一组钢筋的中心上方,但不在该组中特定钢筋的上方,即我无法找到由提供给悬停的QBarSet指定的钢筋的位置()插槽。
QtCharts::QChart* ScenarioChart = new QtCharts::QChart();
QtCharts::QBarSeries* ScenarioBarSeries = new QtCharts::QBarSeries();
QVector<QtCharts::QBarSet*> ScenarioBarSets;
:
for(auto it = this->ScenarioBarSets.begin(); it != this->ScenarioBarSets.end(); ++it)
this->ScenarioBarSeries->append(*it);
this->ScenarioChart->addSeries(ScenarioBarSeries);
:
this->setMouseTracking(true);
this->ScenarioChart->setAcceptHoverEvents(true);
QObject::connect(this->ScenarioBarSeries, SIGNAL(hovered(bool, int, QBarSet*)), this, SLOT(SlotShowGraphic(bool, int, QBarSet*)));
:
:
void TabScenario::SlotShowGraphic(bool Status, int Index, QBarSet* Barset)
{
if (Status){
QtCharts::QBarSeries* TempBarSeries = new QBarSeries;
TempBarSeries->append(Barset);
QPointF ChartMousePosF_1 = this->ScenarioChart->mapToPosition(QPointF(Index, Barset->at(Index)), TempBarSeries); //Option 1
QPointF ChartMousePosF_2 = this->ScenarioChart->mapToPosition(QPointF(Index, Barset->at(Index)), this->ScenarioBarSeries); //Option 2
:
}
}
我尝试使用QCursor :: pos()失败。我还看了Callout示例,但线形图悬停事件直接提供了QPointF:
void View::tooltip(QPointF point, bool state)
问题:如何确定QBarSeries的悬停光标的位置?