1

SliderQtQuick.Controls のみhandleがクリック可能で、ドラッグに使用できるusingを実装したいと考えていhandleます。をクリックしてもgroove、何も起こらないはずhandleです。の をのみに制限するmouseAreaにはどうすればよいですか?Sliderhandle

以下の例でSliderは、 は全体でクリック可能でありSlider widthheight:

import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3

Window {
    id: mainItem
    width: 800
    height: 400
    visible: true

    Slider{
        id: autoSlider
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        maximumValue: 1.0
        value: 0
        updateValueWhileDragging : false

        style: SliderStyle {
            groove: Rectangle {
                implicitWidth: 350
                implicitHeight: 8
                color: "gray"
                radius: 8
            }
            handle: Rectangle {
                anchors.centerIn: parent
                color: control.pressed ? "white" : "lightgray"
                border.color: "gray"
                border.width: 2
                implicitWidth: 45
                implicitHeight: 45
                radius: 12
            }
        }
    }
}

「..\qml\QtQuick\Controls」フォルダのテンプレートを変更しようと思ったSlider.qmlのですが、どうすればいいのかよくわかりませんでした。

私のすべての検索努力は何にもつながりません。どんな助けでも大歓迎です。

4

1 に答える 1

1

私は間違っているかもしれませんが、これはすべてのデスクトップ プラットフォームでのスライダーの動作に反すると思います。これは、使いやすさの理由から考慮する必要があります。それはさておき、試してみましょう:

diff --git a/src/controls/Slider.qml b/src/controls/Slider.qml
index 20d1102..da6f051 100644
--- a/src/controls/Slider.qml
+++ b/src/controls/Slider.qml
@@ -258,7 +258,7 @@ Control {
         }

         onPositionChanged: {
-            if (pressed)
+            if (pressed && handleHovered)
                 updateHandlePosition(mouse, preventStealing)

マウスがハンドルの外側にあることを意味するため、ハンドルがホバーされていないときにハンドルの位置を変更したくありません。

             var point = mouseArea.mapToItem(fakeHandle, mouse.x, mouse.y)
@@ -272,18 +272,21 @@ Control {
             if (handleHovered) {
                 var point = mouseArea.mapToItem(fakeHandle, mouse.x, mouse.y)
                 clickOffset = __horizontal ? fakeHandle.width/2 - point.x : fakeHandle.height/2 - point.y
+
+                pressX = mouse.x
+                pressY = mouse.y
+                updateHandlePosition(mouse, !Settings.hasTouchScreen)
             }
-            pressX = mouse.x
-            pressY = mouse.y
-            updateHandlePosition(mouse, !Settings.hasTouchScreen)
         }

次に、ハンドル位置の更新をハンドルのif (handleHovered)条件内に移動しonPressedます。

         onReleased: {
-            updateHandlePosition(mouse, Settings.hasTouchScreen)
-            // If we don't update while dragging, this is the only
-            // moment that the range is updated.
-            if (!slider.updateValueWhileDragging)
-                range.position = __horizontal ? fakeHandle.x : fakeHandle.y;
+            if (handleHovered) {
+                updateHandlePosition(mouse, Settings.hasTouchScreen)
+                // If we don't update while dragging, this is the only
+                // moment that the range is updated.
+                if (!slider.updateValueWhileDragging)
+                    range.position = __horizontal ? fakeHandle.x : fakeHandle.y;
+            }
             clickOffset = 0
             preventStealing = false
         }

onReleased最後に、ハンドラーに同様の変更を加えます。

これにより、文字通り、端が少し荒いですが、必要なものが得られます. 相互作用は100%ではないと思いますが、試してみてください。もう少し実験すれば、完全に機能するようになるはずです。

別のハッキーなオプションは、スライダー自体のにある、ハンドルSlider.qmlのいずれかの側を持つように変更することです。これらのそれぞれは、ハンドルの両側の利用可能なスペースを埋め、溝がそれらの領域で受け取るすべてのマウス イベントを効果的に盗みます。MouseArea

于 2015-09-23T17:41:07.460 に答える