Results 1 to 7 of 7

Thread: qml listView key navigation not working setting focus: true

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    jfinn88 Guest

    Default Re: qml listView key navigation not working setting focus: true

    I tried both those... still doesn't seem to get focus... I did find a slight work around by placing the key navigation above the listView item.... in my Component (delegate).

    I check to see if the listView has active focus it returns true but when I comment out my key calls I can't navigate in list view. Documentation claims that focus just needs to be active to use key navigation...

    below you see some commented out code that’s some of the different ways I have tired to get key navigation for the listView enabled

    updated code:

    Qt Code:
    1. //---User Event log Component---//
    2. Item {
    3. visible: true
    4. id:userevent_item
    5. enabled: true
    6. // Component.onCompleted: {
    7. // listView.forceActiveFocus();
    8. // console.log("Outer Item onCompleted activeFocus: "+activeFocus)
    9. // }
    10. Rectangle {
    11. id: view_rect
    12. anchors.centerIn: parent
    13. width: 1100
    14. height: 600
    15. radius: 10
    16. border.width:4
    17. border.color: "black"
    18. layer.enabled: true
    19. enabled: true
    20. focus:true
    21.  
    22. Component.onCompleted: {
    23. UserEventLog.init();
    24. // listView.forceActiveFocus();
    25. // console.log("viewRect onCompleted activeFocus: "+activeFocus)
    26. }
    27.  
    28.  
    29. FocusScope{
    30. anchors.fill:parent
    31. focus: true
    32. Label {
    33. id: userEventTitle_label
    34. color: "#000000"
    35. text: qsTr("User Event Log")
    36. anchors.top: parent.top
    37. anchors.topMargin: 5
    38. anchors.horizontalCenter: parent.horizontalCenter
    39. anchors.verticalCenter: parent.verticalCenter
    40. horizontalAlignment: Text.AlignLeft
    41. font.pointSize: 22
    42. font.bold: true
    43. }
    44.  
    45. Component {
    46. id: msgDelegate
    47. Item {
    48. id: active_eventMsg
    49. focus: true
    50. anchors.left: parent.left
    51. anchors.leftMargin: 5
    52. anchors.right: parent.right
    53. anchors.rightMargin:5
    54. height: 30
    55. Keys.onDownPressed: listView.incrementCurrentIndex()
    56. Keys.onUpPressed: listView.decrementCurrentIndex()
    57. KeyNavigation.tab: userNameTextField
    58. Component.onCompleted: {
    59. listView.forceActiveFocus();
    60. console.log("msgDelegate onCompleted activeFocus: "+listView.activeFocus)
    61. }
    62. Rectangle{
    63. id: id_rect
    64. anchors.top: parent.top
    65. anchors.left: parent.left
    66. anchors.leftMargin: 2
    67. width: id_col.width
    68. height: parent.height
    69. color: "#00000000"
    70. Text {
    71. color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
    72. anchors.fill: parent
    73. verticalAlignment: Text.AlignVCenter
    74. horizontalAlignment: Text.AlignLeft
    75. text: id;
    76. font.pixelSize: 18
    77. }
    78. }
    79. Rectangle{
    80. id: userName_rect
    81. anchors.top: parent.top
    82. anchors.left: id_rect.right
    83. anchors.leftMargin: 2
    84. width: userName_col.width
    85. height: parent.height
    86. color: "#00000000"
    87. Text {
    88. color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
    89. anchors.fill: parent
    90. anchors.leftMargin: 2
    91. verticalAlignment: Text.AlignVCenter
    92. horizontalAlignment: Text.AlignLeft
    93. text: userName;
    94. font.pixelSize: 18
    95. }
    96. }
    97. Rectangle{
    98. id: eventMsg_rect
    99. anchors.top: parent.top
    100. anchors.left: userName_rect.right
    101. anchors.leftMargin: 2
    102. width: eventMsg_col.width
    103. height: parent.height
    104. color: "#00000000"
    105. Text {
    106. color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
    107. anchors.fill: parent
    108. anchors.leftMargin: 2
    109. verticalAlignment: Text.AlignVCenter
    110. horizontalAlignment: Text.AlignLeft
    111. text: eventMessage;
    112. font.pixelSize: 18
    113. }
    114. }
    115. Rectangle{
    116. id: dateTime_rect
    117. anchors.top: parent.top
    118. anchors.left: eventMsg_rect.right
    119. anchors.leftMargin: 2
    120. width: dateTime_col.width
    121. anchors.right: parent.right
    122. height: parent.height
    123. color: "#00000000"
    124. Text {
    125. color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
    126. anchors.fill: parent
    127. anchors.leftMargin: 2
    128. verticalAlignment: Text.AlignVCenter
    129. horizontalAlignment: Text.AlignLeft
    130. text: dateTime;
    131. font.pixelSize: 18
    132. }
    133. }
    134. }
    135. }
    136.  
    137. Rectangle {
    138. id: listView_rect
    139. focus: true
    140. radius: 8
    141. anchors.top: eventMsg_panel.bottom
    142. anchors.topMargin: 2
    143. anchors.bottom: parent.bottom
    144. anchors.bottomMargin: 65
    145. anchors.left:parent.left
    146. anchors.leftMargin: 5
    147. anchors.right:parent.right
    148. anchors.rightMargin: 6
    149. //Keys.onPressed: console.log("key pressed activeFocus: ", activeFocus)
    150. //Keys.onDownPressed: listView.incrementCurrentIndex()
    151. //Keys.onUpPressed: listView.decrementCurrentIndex()
    152. border{
    153. color: "black"
    154. width: 3
    155. }
    156. ScrollView{
    157. id: userEvent_scrollView
    158. anchors.fill: parent
    159. anchors.bottomMargin: 2
    160. anchors.topMargin: 2.5
    161. anchors.rightMargin: 2
    162. anchors.leftMargin: 2.5
    163. flickableItem.interactive: true
    164. //Keys.onPressed: console.log("scrollView key pressed activeFocus: ", activeFocus)
    165. //Keys.onDownPressed: listView.incrementCurrentIndex()
    166. //Keys.onUpPressed: listView.decrementCurrentIndex()
    167. ListView {
    168. id: listView
    169. focus: true
    170. anchors.fill: parent
    171. model: UserEventLog
    172. delegate: msgDelegate
    173. keyNavigationWraps: true
    174. KeyNavigation.tab: userNameTextField
    175. orientation : "Vertical"
    176. snapMode: ListView.SnapToItem
    177. boundsBehavior: Flickable.StopAtBounds
    178. clip: true;
    179. highlightMoveVelocity: 2000
    180. highlight: Rectangle{
    181. radius: 7;
    182. color: "red"
    183. }
    184. Component.onCompleted: {
    185. listView.forceActiveFocus();
    186. console.log("listView onCompleted activeFocus: "+activeFocus)
    187. }
    188. //Keys.onPressed: console.log("listView key pressed activeFocus: ", activeFocus)
    189. //Keys.onDownPressed: listView.incrementCurrentIndex()
    190. //Keys.onUpPressed: listView.decrementCurrentIndex()
    191. }
    192. }
    193. }
    194. }
    195. }
    196. }
    197. //---------------------------End of User Event Log Component-------------------------------//
    To copy to clipboard, switch view to plain text mode 
    Last edited by jfinn88; 28th September 2016 at 19:37.

Similar Threads

  1. Replies: 2
    Last Post: 16th May 2016, 23:50
  2. ListView - ListView communication
    By MarkoSan in forum Qt Quick
    Replies: 1
    Last Post: 30th October 2015, 10:18
  3. Replies: 11
    Last Post: 16th October 2015, 14:34
  4. QPushButton::setEnabled( true ) not working
    By unshaven in forum Newbie
    Replies: 1
    Last Post: 9th August 2012, 06:27
  5. Replies: 27
    Last Post: 13th September 2007, 09:01

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
  •  
Qt is a trademark of The Qt Company.