Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-109402

When importing a specific Qt Quick Controls style, things like standalone attached types aren't available

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 6.5
    • Quick: Controls 2
    • None

    Description

      Noticed when trying to use SplitHandle with compile-time style selection:

      import QtQuick
      import QtQuick.Window
      import QtQuick.Controls.Basic
      import QtQuick.Layouts
      
      Window {
          id: window
          width: 1280
          height: 720
          visible: true
      
          SplitView {
              anchors.fill: parent
              handle: Rectangle {
                  implicitWidth: 10
                  color: "tomato"
                  opacity: SplitHandle.hovered || SplitHandle.pressed ? 1.0 : 0.0
      
                  Behavior on opacity {
                      OpacityAnimator {
                          duration: 900
                          easing.type: Easing.Linear
                      }
                  }
              }
      
              Rectangle {
                  implicitWidth: 32
                  implicitHeight: 32
                  color: "steelblue"
              }
              Rectangle {
                  implicitWidth: 32
                  implicitHeight: 32
                  color: "navajowhite"
              }
          }
      }
      
      qrc:/main.qml:17: ReferenceError: SplitHandle is not defined
      

      Attached types that piggy-back on an existing type (like SplitView) work because the Basic style can define SplitView.qml, but that's not possible with SplitHandle, which is purely an attached type.

      This patch is enough to fix it:

      diff --git a/src/quickcontrols/basic/CMakeLists.txt b/src/quickcontrols/basic/CMakeLists.txt
      index e45b6d09c0..c6fdf532d3 100644
      --- a/src/quickcontrols/basic/CMakeLists.txt
      +++ b/src/quickcontrols/basic/CMakeLists.txt
      @@ -155,6 +155,8 @@ qt_internal_add_qml_module(qtquickcontrols2basicstyleplugin
           CLASS_NAME QtQuickControls2BasicStylePlugin
           DEPENDENCIES
               QtQuick/auto
      +    IMPORTS
      +        QtQuick.Templates/auto
           PLUGIN_TARGET qtquickcontrols2basicstyleplugin
           NO_PLUGIN_OPTIONAL
           NO_GENERATE_PLUGIN_SOURCE
      

      Attachments

        Issue Links

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: