Hi,
I am subclassing QChart. But QChart does not seem to receive keypress events.
class Chart : public QChart
{
public:
explicit Chart
(QGraphicsItem *parent
= 0, Qt
::WindowFlags wFlags
= 0);
protected:
private:
};
class Chart : public QChart
{
public:
explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
protected:
void keyPressEvent(QKeyEvent *event);
void mousePressEvent (QGraphicsSceneMouseEvent* me);
private:
};
To copy to clipboard, switch view to plain text mode
: QChart(QChart::ChartTypeCartesian, parent, wFlags)
{
setFlags(ItemIsFocusable| ItemIsSelectable | ItemIsMovable | ItemSendsScenePositionChanges);
setAcceptHoverEvents(true);
setFocus();
}
{
qDebug("keyPressEvent");
QChart::keyPressEvent(event);
}
{
qDebug("mousePressEvent");
QChart::mousePressEvent(me);
}
Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
: QChart(QChart::ChartTypeCartesian, parent, wFlags)
{
setFlags(ItemIsFocusable| ItemIsSelectable | ItemIsMovable | ItemSendsScenePositionChanges);
setAcceptHoverEvents(true);
setFocus();
}
void Chart::keyPressEvent(QKeyEvent *event)
{
qDebug("keyPressEvent");
QChart::keyPressEvent(event);
}
void Chart::mousePressEvent(QGraphicsSceneMouseEvent *me)
{
qDebug("mousePressEvent");
QChart::mousePressEvent(me);
}
To copy to clipboard, switch view to plain text mode
I am adding the item into a QGraphicsscene:
sceneGraph->setSceneRect(0,0,1024,768);
sceneGraph->addItem(chart);
ui->graphicsView->setScene(sceneGraph);
QGraphicsScene* sceneGraph= new QGraphicsScene();
sceneGraph->setSceneRect(0,0,1024,768);
sceneGraph->addItem(chart);
ui->graphicsView->setScene(sceneGraph);
To copy to clipboard, switch view to plain text mode
It gets mouse events but not key press events.
Any idea what could be the reason?
Thanks.
Bookmarks