the Function setBuddy() doesn't work



  • Here is my code

    label = new QLabel(tr("Find &what: "));
    lineEdit = new QLineEdit;
    label->setBuddy(lineEdit);
    

    It compiled and run well,bu when i pressed Alt+w
    nothing happened~how can i figure out what's wrong with my code!

    ps: the correct action: the focus jumps to the lineEdit field when the user presses Alt+w,



  • I konw the answer now - -.
    my original code:

    label = new QLabel(tr("Find &What: ");
    

    I change uppercase 'W' to lowercase 'w',my program works correctly.
    my question is " why i can't write the uppercase 'W' "?


  • Moderators

    actually this shouldn't matter.
    Test it with other letters. Maybe something is stealing this specific keyevent from the label.



  • @ozzy said:

    my question is " why i can't write the uppercase 'W' "?

    As shown here http://doc.qt.io/qt-4.8/qlabel.html#setBuddy
    focus jumps to the Name field when the user presses Alt+N because his name sarts with &N
    In your case which is &What equals Alt+W



  • Thank you,very much.
    &That and &that both work well~


  • Moderators

    @ozzy said:

    Thank you,very much.
    &That and &that both work well~

    so now the question is why the label doesn't receive the ALT+W keyevent. I just can guess without knowing your code. And even then it probably would be the fastest to debug the issue and check where the keyevent is consumed.



  • How to check where the keyevent is consumed?
    I don't hava any thought.



  • @ozzy

    public :
    void keyPressEvent(QKeyEvent* e)
        {
            qDebug() << "Key Pressed is:" <<  e->text());
        }

  • Moderators

    @ozzy said:

    How to check where the keyevent is consumed?
    I don't hava any thought.

    That's how i would do it, but if you don't feel familiar with Qt source code or debugging at all it will be somewhat hard.

    1. Install an event filter on qApp
    2. in the event filter check for keypress events where the ALT key and W keys are pressed and set a breakpoint
    3. when the breakpoint hits step out of the method and continue into the receivers and check which one consumes the event

    on the other hand - if possible - you can simplify your application until it works and re-add the parts and check when it stops working.

    @Ratzz:
    I doubt that this code actually helps solving this issue, since the label would receive the event the issue wouldn't exist in the first place.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.