Results 1 to 2 of 2

Thread: Derived Class for QScrollArea Concerning Keypad Navigation on Embedded Linux Platform

  1. #1
    Join Date
    Jan 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Derived Class for QScrollArea Concerning Keypad Navigation on Embedded Linux Platform

    I got a question.

    Here's a long story short:

    We started on a project for an Embedded Linux platform. This platform does not have a mouse or keyboard. It just has a keypad 0-9, Up, Down, Left, Right, Enter and Cancel buttons.

    Using Qt 4.7.0, we couldn't figure out why keypad navigation wouldn't work with the Arrow keys (I believe it was the Up/Down keys that were not working).

    We then discovered the magic of grabkeyboard() and releasekeyboard(). It was at this point that Pandora's box was opened.

    So these calls got spread throughout the build, what a headache. Now after doing some thinking/research, I'm going back and cleaning this up.

    As I understand it today, without the grabkeyboard() and releasekeyboard() calls in a build, Qt will deliever QKeyEvent(s) to a widget that has focus.

    Now one of our screens within our application may be a parent widget, but a QKeyEvent will get delivered to a child widget FIRST before the parent widget.

    Some QWidget(s) may filter or consume out certain QKeyEvent(s) by design (not sure why). For QKeyEvent(s) that are delivered to a child widget that are NOT consumed by design get passed onto the parent widget if it hits a:

    QWidget::keyPressEvent(ptr_to_QKeyEvent) method call.

    From what I gather, its a matter of understanding the parent/child relationship or parent/child chain which can have multiple levels.

    OK, given the story and an explanation of my ***understanding*** above, I've dervied some qwidget classes that override the keyPressEvent to not filter
    out some QKeyEvent(s) (Qt::Key_Up and Qt::Key_Down), but to pass it onto the parent.

    My question:

    If I have a derived class for a QScrollArea, that has an empty constructor and a very limited switch statement within the keyPressEvent as such:


    void myScrollArea::keyPressEvent(QKeyEvent *e)
    {
    switch(e->key())
    {
    case Qt::Key_Up:
    case Qt::Key_Down:
    QScrollArea::keyPressEvent(e);
    QWidget::keyPressEvent(e);
    break;

    default:
    QScrollArea::keyPressEvent(e);
    break;
    }
    }

    Is it OK to have two method calls for the Qt::Key_Up and Qt::Key_Down keys? The QScrollArea::keyPressEvent(e) call is to maintain the natural behavior for the class. The QWidget::keyPressEvent(e) call is so the the Up/Down keys are not filtered out by myScollArea, but gets passed onto its parent.

    I'm concerned that both method calls may try to delete the pointer at some point. All my testing seems to be going OK though.

    Just being cautious.

    Thanks for your patience and any help for answering this question.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Derived Class for QScrollArea Concerning Keypad Navigation on Embedded Linux Plat

    why aren't you using eventfilter instead? Seems like that is what you are trying to do.

    I would think events would only be deleted from the main loop so it wont matter how many parent class implementations you call.
    Last edited by amleto; 28th August 2012 at 20:17.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Font Size Problem on Qt 4.7 on Embedded Linux Platform
    By samueleforconi in forum Qt Programming
    Replies: 0
    Last Post: 21st May 2012, 16:52
  2. QT embedded QtWebKit on Linux 2.6.22, including MIPS platform
    By Thành Viên Mới in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 11th November 2010, 03:43
  3. Replies: 3
    Last Post: 14th August 2010, 04:04
  4. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36
  5. How Qt/Embedded detects the keypad input from device?
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 4th April 2006, 07:08

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.