Drawing point to point Lines dynamically using canvasHow to properly use QQuickItem::stackBefore() to reorder items in GridLayout?How to draw line - not on Canvas, just object?Bézier spline interpolation between two nodes: How to find suitable anchor points?Collision point detection in Qt Graphics FrameworkCanvas Drawing in QML - QtDraw a line in a circular path in QML?Drawing shapes using canvascanvas transparency in QtDrawing segments on QML canvasQML Canvas: problem with drawing of SVG image with lines containing arrows
Select items in a list that contain criteria
Why is the application of an oracle function not a measurement?
Will TSA allow me to carry a Continuous Positive Airway Pressure (CPAP)/sleep apnea device?
Does an ice chest packed full of frozen food need ice?
Shape-shifting using particle-sized 'building blocks'
siunitx error: Invalid numerical input
Does Lightning Network has concept of continuous stream of value?
What risks are there when you clear your cookies instead of logging off?
How do I write "Show, Don't Tell" as an Asperger?
Do any instruments not produce overtones?
How hard would it be to convert a glider into an powered electric aircraft?
What can plausibly explain many of my very long and low-tech bridges?
How to retract the pitched idea from employer?
Why don't B747s start takeoffs with full throttle?
Are go-arounds prohibited at St Barth (TFFJ)?
Traffic law UK, pedestrians
Strat tremolo bar has tightening issues
Are there any existing monsters I can use as a basis for a baby skeleton statblock?
Why does the Schrödinger equation work so well for the Hydrogen atom despite the relativistic boundary at the nucleus?
QGIS Draw by rule
How to pass a regex when finding a directory path in bash?
Last survivors from different time periods living together
Can a user sell my software (MIT license) without modification?
You've spoiled/damaged the card
Drawing point to point Lines dynamically using canvas
How to properly use QQuickItem::stackBefore() to reorder items in GridLayout?How to draw line - not on Canvas, just object?Bézier spline interpolation between two nodes: How to find suitable anchor points?Collision point detection in Qt Graphics FrameworkCanvas Drawing in QML - QtDraw a line in a circular path in QML?Drawing shapes using canvascanvas transparency in QtDrawing segments on QML canvasQML Canvas: problem with drawing of SVG image with lines containing arrows
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to make a simple Graphics Application in which I can create different Shapes like (rectangles, Circles, Triangles) and also a line (from one point to another) dynamically. For the first 3 I havent had any Problems at all. For the rect I just defined a component Rectangle and created it with create component inside the onClicked Handler of the MouseArea for my drawing area. For the triangle I worked with canvas to draw the triangle and created the component also with create component and using the onClicked handler. I mostly passed mouse.x and mouse.y to create the shapes wherever I wanted. Now for the Line I would like to define the startpoint when the mousearea is clicked and the endpoint when released. As soon as it is released I want to draw the line(using canvas). How do I do this?
For reference I added a screenshot of how I created my other items:

qt qml
add a comment |
I am trying to make a simple Graphics Application in which I can create different Shapes like (rectangles, Circles, Triangles) and also a line (from one point to another) dynamically. For the first 3 I havent had any Problems at all. For the rect I just defined a component Rectangle and created it with create component inside the onClicked Handler of the MouseArea for my drawing area. For the triangle I worked with canvas to draw the triangle and created the component also with create component and using the onClicked handler. I mostly passed mouse.x and mouse.y to create the shapes wherever I wanted. Now for the Line I would like to define the startpoint when the mousearea is clicked and the endpoint when released. As soon as it is released I want to draw the line(using canvas). How do I do this?
For reference I added a screenshot of how I created my other items:

qt qml
4
You should create a MCVE (easy with QML), and provide the code as text. Also, what exactly is your problem? Are you unable to get the coordinate? Do you get the coordinates but are unable to pass them to canvas? Do you actually get everything necessary to your Canvas but fail to draw the line correctly?
– hyde
Mar 24 at 16:01
1
show your code as text
– eyllanesc
Mar 24 at 18:36
add a comment |
I am trying to make a simple Graphics Application in which I can create different Shapes like (rectangles, Circles, Triangles) and also a line (from one point to another) dynamically. For the first 3 I havent had any Problems at all. For the rect I just defined a component Rectangle and created it with create component inside the onClicked Handler of the MouseArea for my drawing area. For the triangle I worked with canvas to draw the triangle and created the component also with create component and using the onClicked handler. I mostly passed mouse.x and mouse.y to create the shapes wherever I wanted. Now for the Line I would like to define the startpoint when the mousearea is clicked and the endpoint when released. As soon as it is released I want to draw the line(using canvas). How do I do this?
For reference I added a screenshot of how I created my other items:

qt qml
I am trying to make a simple Graphics Application in which I can create different Shapes like (rectangles, Circles, Triangles) and also a line (from one point to another) dynamically. For the first 3 I havent had any Problems at all. For the rect I just defined a component Rectangle and created it with create component inside the onClicked Handler of the MouseArea for my drawing area. For the triangle I worked with canvas to draw the triangle and created the component also with create component and using the onClicked handler. I mostly passed mouse.x and mouse.y to create the shapes wherever I wanted. Now for the Line I would like to define the startpoint when the mousearea is clicked and the endpoint when released. As soon as it is released I want to draw the line(using canvas). How do I do this?
For reference I added a screenshot of how I created my other items:

qt qml
qt qml
asked Mar 24 at 15:08
SmallforestSmallforest
224
224
4
You should create a MCVE (easy with QML), and provide the code as text. Also, what exactly is your problem? Are you unable to get the coordinate? Do you get the coordinates but are unable to pass them to canvas? Do you actually get everything necessary to your Canvas but fail to draw the line correctly?
– hyde
Mar 24 at 16:01
1
show your code as text
– eyllanesc
Mar 24 at 18:36
add a comment |
4
You should create a MCVE (easy with QML), and provide the code as text. Also, what exactly is your problem? Are you unable to get the coordinate? Do you get the coordinates but are unable to pass them to canvas? Do you actually get everything necessary to your Canvas but fail to draw the line correctly?
– hyde
Mar 24 at 16:01
1
show your code as text
– eyllanesc
Mar 24 at 18:36
4
4
You should create a MCVE (easy with QML), and provide the code as text. Also, what exactly is your problem? Are you unable to get the coordinate? Do you get the coordinates but are unable to pass them to canvas? Do you actually get everything necessary to your Canvas but fail to draw the line correctly?
– hyde
Mar 24 at 16:01
You should create a MCVE (easy with QML), and provide the code as text. Also, what exactly is your problem? Are you unable to get the coordinate? Do you get the coordinates but are unable to pass them to canvas? Do you actually get everything necessary to your Canvas but fail to draw the line correctly?
– hyde
Mar 24 at 16:01
1
1
show your code as text
– eyllanesc
Mar 24 at 18:36
show your code as text
– eyllanesc
Mar 24 at 18:36
add a comment |
1 Answer
1
active
oldest
votes
The MouseArea has a released signal as well. Whenever your selectedIndex says "line", store the x and y in the onPressed handler and only create the line in the onReleased handler, using the stored position
MouseArea
property var startPoint
onPressed:
if(selectedShape.currentIndex === 3)
startPoint = Qt.point(mouse.x, mouse.y)
onReleased:
if(selectedShape.currentIndex === 3 && startPoint !== undefined)
createLine(startPoint, Qt.point(mouse.x, mouse.y) //your function goes here
startPoint = undefined
PS. don't paste code as images!
Thanks this is what I was looking for.
– Smallforest
Mar 27 at 10:03
add a comment |
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%2f55325196%2fdrawing-point-to-point-lines-dynamically-using-canvas%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The MouseArea has a released signal as well. Whenever your selectedIndex says "line", store the x and y in the onPressed handler and only create the line in the onReleased handler, using the stored position
MouseArea
property var startPoint
onPressed:
if(selectedShape.currentIndex === 3)
startPoint = Qt.point(mouse.x, mouse.y)
onReleased:
if(selectedShape.currentIndex === 3 && startPoint !== undefined)
createLine(startPoint, Qt.point(mouse.x, mouse.y) //your function goes here
startPoint = undefined
PS. don't paste code as images!
Thanks this is what I was looking for.
– Smallforest
Mar 27 at 10:03
add a comment |
The MouseArea has a released signal as well. Whenever your selectedIndex says "line", store the x and y in the onPressed handler and only create the line in the onReleased handler, using the stored position
MouseArea
property var startPoint
onPressed:
if(selectedShape.currentIndex === 3)
startPoint = Qt.point(mouse.x, mouse.y)
onReleased:
if(selectedShape.currentIndex === 3 && startPoint !== undefined)
createLine(startPoint, Qt.point(mouse.x, mouse.y) //your function goes here
startPoint = undefined
PS. don't paste code as images!
Thanks this is what I was looking for.
– Smallforest
Mar 27 at 10:03
add a comment |
The MouseArea has a released signal as well. Whenever your selectedIndex says "line", store the x and y in the onPressed handler and only create the line in the onReleased handler, using the stored position
MouseArea
property var startPoint
onPressed:
if(selectedShape.currentIndex === 3)
startPoint = Qt.point(mouse.x, mouse.y)
onReleased:
if(selectedShape.currentIndex === 3 && startPoint !== undefined)
createLine(startPoint, Qt.point(mouse.x, mouse.y) //your function goes here
startPoint = undefined
PS. don't paste code as images!
The MouseArea has a released signal as well. Whenever your selectedIndex says "line", store the x and y in the onPressed handler and only create the line in the onReleased handler, using the stored position
MouseArea
property var startPoint
onPressed:
if(selectedShape.currentIndex === 3)
startPoint = Qt.point(mouse.x, mouse.y)
onReleased:
if(selectedShape.currentIndex === 3 && startPoint !== undefined)
createLine(startPoint, Qt.point(mouse.x, mouse.y) //your function goes here
startPoint = undefined
PS. don't paste code as images!
answered Mar 25 at 8:30
AmfasisAmfasis
873718
873718
Thanks this is what I was looking for.
– Smallforest
Mar 27 at 10:03
add a comment |
Thanks this is what I was looking for.
– Smallforest
Mar 27 at 10:03
Thanks this is what I was looking for.
– Smallforest
Mar 27 at 10:03
Thanks this is what I was looking for.
– Smallforest
Mar 27 at 10:03
add a comment |
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.
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%2f55325196%2fdrawing-point-to-point-lines-dynamically-using-canvas%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
4
You should create a MCVE (easy with QML), and provide the code as text. Also, what exactly is your problem? Are you unable to get the coordinate? Do you get the coordinates but are unable to pass them to canvas? Do you actually get everything necessary to your Canvas but fail to draw the line correctly?
– hyde
Mar 24 at 16:01
1
show your code as text
– eyllanesc
Mar 24 at 18:36