Results 1 to 5 of 5

Thread: A bug about Keyboard Focus in Qt Quick in QT 5.10 document?

  1. #1
    Join Date
    Feb 2018
    Posts
    4
    Thanks
    1

    Default A bug about Keyboard Focus in Qt Quick in QT 5.10 document?

    I am reading the Qt doc to learn the Keyboard Focus in Qt Quick! I run the code which from the document. However, the result is different form the document! The codes are as follows.

    main.qml

    Qt Code:
    1. //Window code that imports MyWidget
    2. Rectangle {
    3. id: window
    4. color: "white"; width: 240; height: 150
    5.  
    6. Column {
    7. anchors.centerIn: parent; spacing: 15
    8.  
    9. MyWidget {
    10. focus: true //set this MyWidget to receive the focus
    11. color: "lightblue"
    12. }
    13. MyWidget {
    14. color: "palegreen"
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    MyWidget.qml

    Qt Code:
    1. Rectangle {
    2. id: widget
    3. color: "lightsteelblue"; width: 175; height: 25; radius: 10; antialiasing:
    4. true
    5. Text { id: label; anchors.centerIn: parent}
    6. focus: true
    7. Keys.onPressed: {
    8. if (event.key == Qt.Key_A)
    9. label.text = 'Key A was pressed'
    10. else if (event.key == Qt.Key_B)
    11. label.text = 'Key B was pressed'
    12. else if (event.key == Qt.Key_C)
    13. label.text = 'Key C was pressed'
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    The pic1 is the result form doc. And the pic2 is the result of my running which i just copy the code from doc and run it.


    pic1


    pic2




    Is it a bug? Why the result are different?

    **The doc said**:

    We want the first MyWidget object to have the focus, so we set its focus property to true. However, by running the code, we can confirm that the second widget receives the focus.

    Looking at both MyWidget and window code, the problem is evident - there are three types that set the focus property to true. The two MyWidgets set the focus to true and the window component also sets the focus. Ultimately, only one type can have keyboard focus, and the system has to decide which type receives the focus. When the second MyWidget is created, it receives the focus because it is the last type to set its focus property to true.

    **My question**:

    1.Why the result are different?In my result the first widget receives the focus.


    2.Also, what is the meaning of"because it is the last type to set its focus property to true"in doc?

    **The doc you can get from here!**
    http://doc.qt.io/qt-5/qtquick-input-focus.html

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A bug about Keyboard Focus in Qt Quick in QT 5.10 document?

    Your result is what I'd expect to happen. Maybe the docs are outdated. You should be using FocusScope to work around this ambiguity.


    Ad 2. QML evaulates elements in a top-down manner so the bottom-most element will be the last element to try and set its focus property to true. Since only one item can have focus, the docs claim it will be switching from one element to the next as it grabs focus.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2018
    Posts
    4
    Thanks
    1

    Default Re: A bug about Keyboard Focus in Qt Quick in QT 5.10 document?

    Thank you for your answer. As the result is different from the docs. The sentence "because it is the last type to set its focus property to true" is wrong, right? It should be "The first type to set its focus property to true""

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A bug about Keyboard Focus in Qt Quick in QT 5.10 document?

    Quote Originally Posted by mrmuto2 View Post
    The sentence "because it is the last type to set its focus property to true" is wrong, right?
    I would assume so.

    It should be "The first type to set its focus property to true""
    Not quite. It might be that it is so because it is the top-most document of a hierarchy that sets the conflicting focus. Or it might be something different
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    mrmuto2 (27th February 2018)

  6. #5
    Join Date
    Feb 2018
    Posts
    4
    Thanks
    1

    Default Re: A bug about Keyboard Focus in Qt Quick in QT 5.10 document?

    Thank you very much

Similar Threads

  1. Tool Button keyboard focus?
    By ts230 in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2010, 05:31
  2. keyboard focus
    By JeanC in forum Qt Programming
    Replies: 2
    Last Post: 27th June 2008, 15:40
  3. Replies: 2
    Last Post: 24th July 2006, 18:36

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.