Drag the center of an item
I have an Item
that is a little large. I want to resize it when dragging and ensure that the center is always dragged. The following is a trial (In order for simplicity, I don't set the center of the Item
to the mouse position here, neither do I change the size.), however the position x
will be reset immediately after I change it. Is there any way to avoid this.
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello Quick")
Rectangle{
id: item_
width: 300
height: 300
color: "red"
MouseArea{
id: drag_
anchors.fill: parent
drag.target: item_
}
states: State{
when: drag_.drag.active
PropertyChanges {
target: item_
x: 100
y: 100
}
}
onXChanged: console.log("item_.x: ", x)
}
}
The output:
qml: item_.x: 100
qml: item_.x: 0
qml: item_.x: 1
qml: item_.x: 2
qml: item_.x: 3
qml: item_.x: 4
qml: item_.x: 5
qml: item_.x: 6
qml: item_.x: 7
qml: item_.x: 8
qml: item_.x: 10
qt drag-and-drop qml qtquick2 drag
|
show 2 more comments
I have an Item
that is a little large. I want to resize it when dragging and ensure that the center is always dragged. The following is a trial (In order for simplicity, I don't set the center of the Item
to the mouse position here, neither do I change the size.), however the position x
will be reset immediately after I change it. Is there any way to avoid this.
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello Quick")
Rectangle{
id: item_
width: 300
height: 300
color: "red"
MouseArea{
id: drag_
anchors.fill: parent
drag.target: item_
}
states: State{
when: drag_.drag.active
PropertyChanges {
target: item_
x: 100
y: 100
}
}
onXChanged: console.log("item_.x: ", x)
}
}
The output:
qml: item_.x: 100
qml: item_.x: 0
qml: item_.x: 1
qml: item_.x: 2
qml: item_.x: 3
qml: item_.x: 4
qml: item_.x: 5
qml: item_.x: 6
qml: item_.x: 7
qml: item_.x: 8
qml: item_.x: 10
qt drag-and-drop qml qtquick2 drag
Hi there! What is your question specifically? You mention resizing and dragging the centre but then say it's simplified. Is the problem just with theitem_.x
being displaced?
– TrebuchetMS
Nov 19 '18 at 16:35
I think the State is giving you some troubles, when I remove it, the rectangle stays after dragging. Can you live without?
– Amfasis
Nov 19 '18 at 20:26
@TrebuchetMS Resing and dragging the center is the goal. In order to drag the center, I think I need to change x first. If there exists other solutions, then changing x is not necessary.
– cqdjyy01234
Nov 19 '18 at 23:45
@Amfasis perhaps not. I need to reset all properties if drop is not accepted or cancelled .
– cqdjyy01234
Nov 19 '18 at 23:47
@TrebuchetMS what's more, if I don't need to change the size then I don't need to change the center as the mouse may be left outside after resizing.
– cqdjyy01234
Nov 19 '18 at 23:50
|
show 2 more comments
I have an Item
that is a little large. I want to resize it when dragging and ensure that the center is always dragged. The following is a trial (In order for simplicity, I don't set the center of the Item
to the mouse position here, neither do I change the size.), however the position x
will be reset immediately after I change it. Is there any way to avoid this.
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello Quick")
Rectangle{
id: item_
width: 300
height: 300
color: "red"
MouseArea{
id: drag_
anchors.fill: parent
drag.target: item_
}
states: State{
when: drag_.drag.active
PropertyChanges {
target: item_
x: 100
y: 100
}
}
onXChanged: console.log("item_.x: ", x)
}
}
The output:
qml: item_.x: 100
qml: item_.x: 0
qml: item_.x: 1
qml: item_.x: 2
qml: item_.x: 3
qml: item_.x: 4
qml: item_.x: 5
qml: item_.x: 6
qml: item_.x: 7
qml: item_.x: 8
qml: item_.x: 10
qt drag-and-drop qml qtquick2 drag
I have an Item
that is a little large. I want to resize it when dragging and ensure that the center is always dragged. The following is a trial (In order for simplicity, I don't set the center of the Item
to the mouse position here, neither do I change the size.), however the position x
will be reset immediately after I change it. Is there any way to avoid this.
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello Quick")
Rectangle{
id: item_
width: 300
height: 300
color: "red"
MouseArea{
id: drag_
anchors.fill: parent
drag.target: item_
}
states: State{
when: drag_.drag.active
PropertyChanges {
target: item_
x: 100
y: 100
}
}
onXChanged: console.log("item_.x: ", x)
}
}
The output:
qml: item_.x: 100
qml: item_.x: 0
qml: item_.x: 1
qml: item_.x: 2
qml: item_.x: 3
qml: item_.x: 4
qml: item_.x: 5
qml: item_.x: 6
qml: item_.x: 7
qml: item_.x: 8
qml: item_.x: 10
qt drag-and-drop qml qtquick2 drag
qt drag-and-drop qml qtquick2 drag
asked Nov 19 '18 at 15:17
cqdjyy01234
700617
700617
Hi there! What is your question specifically? You mention resizing and dragging the centre but then say it's simplified. Is the problem just with theitem_.x
being displaced?
– TrebuchetMS
Nov 19 '18 at 16:35
I think the State is giving you some troubles, when I remove it, the rectangle stays after dragging. Can you live without?
– Amfasis
Nov 19 '18 at 20:26
@TrebuchetMS Resing and dragging the center is the goal. In order to drag the center, I think I need to change x first. If there exists other solutions, then changing x is not necessary.
– cqdjyy01234
Nov 19 '18 at 23:45
@Amfasis perhaps not. I need to reset all properties if drop is not accepted or cancelled .
– cqdjyy01234
Nov 19 '18 at 23:47
@TrebuchetMS what's more, if I don't need to change the size then I don't need to change the center as the mouse may be left outside after resizing.
– cqdjyy01234
Nov 19 '18 at 23:50
|
show 2 more comments
Hi there! What is your question specifically? You mention resizing and dragging the centre but then say it's simplified. Is the problem just with theitem_.x
being displaced?
– TrebuchetMS
Nov 19 '18 at 16:35
I think the State is giving you some troubles, when I remove it, the rectangle stays after dragging. Can you live without?
– Amfasis
Nov 19 '18 at 20:26
@TrebuchetMS Resing and dragging the center is the goal. In order to drag the center, I think I need to change x first. If there exists other solutions, then changing x is not necessary.
– cqdjyy01234
Nov 19 '18 at 23:45
@Amfasis perhaps not. I need to reset all properties if drop is not accepted or cancelled .
– cqdjyy01234
Nov 19 '18 at 23:47
@TrebuchetMS what's more, if I don't need to change the size then I don't need to change the center as the mouse may be left outside after resizing.
– cqdjyy01234
Nov 19 '18 at 23:50
Hi there! What is your question specifically? You mention resizing and dragging the centre but then say it's simplified. Is the problem just with the
item_.x
being displaced?– TrebuchetMS
Nov 19 '18 at 16:35
Hi there! What is your question specifically? You mention resizing and dragging the centre but then say it's simplified. Is the problem just with the
item_.x
being displaced?– TrebuchetMS
Nov 19 '18 at 16:35
I think the State is giving you some troubles, when I remove it, the rectangle stays after dragging. Can you live without?
– Amfasis
Nov 19 '18 at 20:26
I think the State is giving you some troubles, when I remove it, the rectangle stays after dragging. Can you live without?
– Amfasis
Nov 19 '18 at 20:26
@TrebuchetMS Resing and dragging the center is the goal. In order to drag the center, I think I need to change x first. If there exists other solutions, then changing x is not necessary.
– cqdjyy01234
Nov 19 '18 at 23:45
@TrebuchetMS Resing and dragging the center is the goal. In order to drag the center, I think I need to change x first. If there exists other solutions, then changing x is not necessary.
– cqdjyy01234
Nov 19 '18 at 23:45
@Amfasis perhaps not. I need to reset all properties if drop is not accepted or cancelled .
– cqdjyy01234
Nov 19 '18 at 23:47
@Amfasis perhaps not. I need to reset all properties if drop is not accepted or cancelled .
– cqdjyy01234
Nov 19 '18 at 23:47
@TrebuchetMS what's more, if I don't need to change the size then I don't need to change the center as the mouse may be left outside after resizing.
– cqdjyy01234
Nov 19 '18 at 23:50
@TrebuchetMS what's more, if I don't need to change the size then I don't need to change the center as the mouse may be left outside after resizing.
– cqdjyy01234
Nov 19 '18 at 23:50
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377640%2fdrag-the-center-of-an-item%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377640%2fdrag-the-center-of-an-item%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi there! What is your question specifically? You mention resizing and dragging the centre but then say it's simplified. Is the problem just with the
item_.x
being displaced?– TrebuchetMS
Nov 19 '18 at 16:35
I think the State is giving you some troubles, when I remove it, the rectangle stays after dragging. Can you live without?
– Amfasis
Nov 19 '18 at 20:26
@TrebuchetMS Resing and dragging the center is the goal. In order to drag the center, I think I need to change x first. If there exists other solutions, then changing x is not necessary.
– cqdjyy01234
Nov 19 '18 at 23:45
@Amfasis perhaps not. I need to reset all properties if drop is not accepted or cancelled .
– cqdjyy01234
Nov 19 '18 at 23:47
@TrebuchetMS what's more, if I don't need to change the size then I don't need to change the center as the mouse may be left outside after resizing.
– cqdjyy01234
Nov 19 '18 at 23:50