Results 1 to 2 of 2

Thread: QChart not getting keypress events.

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    205
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default QChart not getting keypress events.

    Hi,

    I am subclassing QChart. But QChart does not seem to receive keypress events.


    Qt Code:
    1. class Chart : public QChart
    2. {
    3. public:
    4. explicit Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
    5.  
    6. protected:
    7. void keyPressEvent(QKeyEvent *event);
    8. void mousePressEvent (QGraphicsSceneMouseEvent* me);
    9.  
    10. private:
    11.  
    12. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
    2. : QChart(QChart::ChartTypeCartesian, parent, wFlags)
    3. {
    4. setFlags(ItemIsFocusable| ItemIsSelectable | ItemIsMovable | ItemSendsScenePositionChanges);
    5. setAcceptHoverEvents(true);
    6. setFocus();
    7. }
    8.  
    9. void Chart::keyPressEvent(QKeyEvent *event)
    10. {
    11. qDebug("keyPressEvent");
    12. QChart::keyPressEvent(event);
    13. }
    14.  
    15. void Chart::mousePressEvent(QGraphicsSceneMouseEvent *me)
    16. {
    17. qDebug("mousePressEvent");
    18. QChart::mousePressEvent(me);
    19. }
    To copy to clipboard, switch view to plain text mode 

    I am adding the item into a QGraphicsscene:

    Qt Code:
    1. QGraphicsScene* sceneGraph= new QGraphicsScene();
    2. sceneGraph->setSceneRect(0,0,1024,768);
    3. sceneGraph->addItem(chart);
    4. 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.

  2. #2
    Join Date
    Dec 2007
    Location
    London
    Posts
    205
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QChart not getting keypress events.

    Ok, i got the problem. MousePress event does not set the focus on ChartItem or it is setting focus on some sub items, i dont know. Setting focus manually after mouse press event solves the issue.

    Qt Code:
    1. void Chart::mousePressEvent(QGraphicsSceneMouseEvent *me)
    2. {
    3. qDebug("mousePressEvent");
    4. QChart::mousePressEvent(me);
    5. setFocus();
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QChart Questions
    By rhb327 in forum Qt Programming
    Replies: 0
    Last Post: 17th May 2017, 11:04
  2. Replies: 1
    Last Post: 6th December 2016, 08:00
  3. KeyPress and KeyRelease events not happening as they should
    By hypnotic401 in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2013, 00:49
  4. KeyPress and KeyRelease Events
    By sattu in forum Qt Programming
    Replies: 8
    Last Post: 30th September 2011, 18:23
  5. Problem with catching keyPress events ?
    By arbi in forum Qt Programming
    Replies: 12
    Last Post: 1st September 2008, 12:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.