各オプションのカスタムデータでQMLに "menu"を作成しようとしています 私のアプリケーションの要件については、QMLファイルを動的にロードする(Qt.createComponent
)必要があります。私が必要とするのは、一部の固定オプションを下部に表示し、上部をクリックすると上部のオプションの下に別のオプションが表示され、上部に保持されます。 単純な例です。QML 'Custom Menu'オプションが上に移動する
Option 4
Option 2
Option 1
そしてOption 4
でクリックしたときに、メニューの変更
Option 4
Option 3
Option 2
Option 1
にそう
Option 4
が上方に移動し、
Option 3
表示されます:私は、このメニューを持っています。
私はすべてのメニューの周りに「影」を持っていたいと思います(その目的のためにDropShadow
コンポーネントを追加しました)。
この簡単なテストコードは、Rectangle
(シャドウに囲まれています)と2つの四角形の内側にあります。固定部(Option 1
,Option 2
)の場合は Rect1
、可動部の場合はRect2
(Option 3
,Option 4
)です。 Rect2
は、Rect1
(z: -1
)の後ろにあり、Option 4
のみが表示され、Option 2
より上に位置しています。 Option 4
をクリックすると、Rect2
が上に移動し、すべてのオプションが表示されます。
は、メインウィンドウの高さは、このRect2
可視高さに依存するので、私は、Rect2
可視高さ、およびメインウィンドウの位置(y
値)を更新する必要があり、それを達成するために。
私はそれを動作させていますが、2つの変数が変更されているため(「固定パネル」が上と下に移動しているため)、多くの動きがあります。
また、私はParallelAnimation
で2つの値を試しましたが、成功しませんでした。
このメニューをスムーズに動かすにはどうしたらいいですか?
Main.qml
:あなたの質問に対する迅速な回答として
import QtQuick 2.0
Rectangle
{
id: window
property variant win: undefined;
Component.onCompleted:
{
var component = Qt.createComponent("TestMenu.qml");
win = component.createObject(window, {"x": 500, "y": 500});
win.show();
}
}
TestMenu.qml:
import QtQuick 2.0
import QtQuick.Window 2.1
import QtGraphicalEffects 1.0
Window {
id: window
flags: Qt.Tool | Qt.FramelessWindowHint
height: panel.height
color: "transparent"
property int radiusShadow: 20
property int iOptionHeight: 30
Rectangle {
id: panel
anchors { centerIn: parent}
height: menu1.height + menu2.heightVisible + 2*radiusShadow
width: window.width - 2*radiusShadow
color: "transparent"
Rectangle {
id: menu1
anchors { bottom: parent.bottom; bottomMargin: radiusShadow }
width: parent.width
height: column1.children.length * iOptionHeight
Column {
id: column1
anchors.fill: parent
Rectangle {
color: "red";
Text { text: qsTr("option 2") }
height: iOptionHeight; width: parent.width
}
Rectangle {
color: "green";
Text { text: qsTr("option 1") }
height: iOptionHeight; width: parent.width
}
}
}
Rectangle {
id: menu2
property int heightVisible: iOptionHeight
anchors { top: parent.top; topMargin: radiusShadow; left: menu1.left }
width: parent.width
height: column2.children.length * iOptionHeight
z: -1
Column {
id: column2
anchors.fill: parent
Rectangle {
id: blue
property bool bOpen: false
color: "blue";
height: iOptionHeight; width: parent.width
Text { text: qsTr("option 4") }
MouseArea {
anchors.fill: parent
onClicked: {
blue.bOpen = !blue.bOpen;
panel.showHideMenu2(blue.bOpen);
}
}
}
Rectangle {
color: "pink";
Text { text: qsTr("option 3") }
height: iOptionHeight; width: parent.width
}
}
}
function showHideMenu2(bShow)
{
if (bShow)
{
window.y -= iOptionHeight
menu2.heightVisible += iOptionHeight;
}
else
{
window.y += iOptionHeight
menu2.heightVisible -= iOptionHeight;
}
}
}
DropShadow {
id: dropShadow
visible: true
anchors.fill: panel
radius: radiusShadow
samples: 24
color: "#40000000"
source: panel
}
}
本当にあなたの助けに感謝し、これらのBehaviorを追加しても問題は解決しません。オプション4をクリックすると、すべてのオプションが少し動いて、効果は本当に悪いです... :( – Diego
計算上のエラーですが、スムーズな動きではありません。問題を記述しようとすると、より具体的になります。 – troyane
私の問題を正しく説明していないと...何を意味するのですか?何か間違っているか分かりません。ありがとうございました – Diego