Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. the Function setBuddy() doesn't work

the Function setBuddy() doesn't work

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ozzy
    wrote on last edited by
    #1

    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,

    1 Reply Last reply
    0
    • O Offline
      O Offline
      ozzy
      wrote on last edited by
      #2

      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' "?

      RatzzR 1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

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

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • O ozzy

          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' "?

          RatzzR Offline
          RatzzR Offline
          Ratzz
          wrote on last edited by
          #4

          @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

          --Alles ist gut.

          1 Reply Last reply
          0
          • O Offline
            O Offline
            ozzy
            wrote on last edited by
            #5

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

            raven-worxR 1 Reply Last reply
            0
            • O ozzy

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

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @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.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              O 1 Reply Last reply
              0
              • raven-worxR raven-worx

                @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.

                O Offline
                O Offline
                ozzy
                wrote on last edited by
                #7

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

                RatzzR raven-worxR 2 Replies Last reply
                0
                • O ozzy

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

                  RatzzR Offline
                  RatzzR Offline
                  Ratzz
                  wrote on last edited by Ratzz
                  #8

                  @ozzy

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

                  --Alles ist gut.

                  1 Reply Last reply
                  1
                  • O ozzy

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

                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by raven-worx
                    #9

                    @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.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved