[vlc-devel] [PATCH 08/14] qml: fix initial focus not beeing set to the first item in NetworkHomeDisplay

Pierre Lamot pierre at videolabs.io
Thu Feb 6 13:56:45 CET 2020


  when the model of the Listview is being updated multiple times, the focus
  remains on the last focussed item, so when we prepend items to our model, this
  moved the initial focussed item, even if we never had the focus on the list.
---
 .../gui/qt/network/qml/NetworkHomeDisplay.qml | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/modules/gui/qt/network/qml/NetworkHomeDisplay.qml b/modules/gui/qt/network/qml/NetworkHomeDisplay.qml
index 1e6b090b2e..6e538a32d7 100644
--- a/modules/gui/qt/network/qml/NetworkHomeDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkHomeDisplay.qml
@@ -52,6 +52,10 @@ Widgets.NavigableFocusScope {
             ctx: mainctx
             sd_source: NetworkDeviceModel.CAT_DEVICES
         }
+
+        onCurrentIndexChanged: {
+            deviceSection.currentIndex = currentIndex
+        }
     }
 
     NetworksSectionSelectableDM{
@@ -61,6 +65,10 @@ Widgets.NavigableFocusScope {
             ctx: mainctx
             sd_source: NetworkDeviceModel.CAT_LAN
         }
+
+        onCurrentIndexChanged: {
+            lanSection.currentIndex = currentIndex
+        }
     }
 
     ScrollView {
@@ -89,6 +97,12 @@ Widgets.NavigableFocusScope {
                 visible: machineDM.items.count !== 0
                 onVisibleChanged: topFocusScope.resetFocus()
 
+                currentIndex: machineDM.currentIndex
+                onFocusChanged: {
+                    if (activeFocus && machineDM.currentIndex === -1 && machineDM.items.count > 0)
+                        machineDM.currentIndex = 0
+                }
+
                 width: flickable.width
                 height: VLCStyle.gridItem_network_height
                 orientation: ListView.Horizontal
@@ -123,6 +137,12 @@ Widgets.NavigableFocusScope {
                 onVisibleChanged: topFocusScope.resetFocus()
                 focus: false
 
+                currentIndex: lanDM.currentIndex
+                onFocusChanged: {
+                    if (activeFocus && lanDM.currentIndex === -1 && lanDM.items.count > 0)
+                        lanDM.currentIndex = 0
+                }
+
                 width: flickable.width
                 height: VLCStyle.gridItem_network_height
                 orientation: ListView.Horizontal
-- 
2.17.1



More information about the vlc-devel mailing list