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;








0















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:
creating the objects



drawing the triangle










share|improve this question

















  • 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

















0















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:
creating the objects



drawing the triangle










share|improve this question

















  • 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













0












0








0








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:
creating the objects



drawing the triangle










share|improve this question














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:
creating the objects



drawing the triangle







qt qml






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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












  • 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












1 Answer
1






active

oldest

votes


















1














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!






share|improve this answer























  • Thanks this is what I was looking for.

    – Smallforest
    Mar 27 at 10:03











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
);



);













draft saved

draft discarded


















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









1














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!






share|improve this answer























  • Thanks this is what I was looking for.

    – Smallforest
    Mar 27 at 10:03















1














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!






share|improve this answer























  • Thanks this is what I was looking for.

    – Smallforest
    Mar 27 at 10:03













1












1








1







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!






share|improve this answer













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!







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 8:30









AmfasisAmfasis

873718




873718












  • 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





Thanks this is what I was looking for.

– Smallforest
Mar 27 at 10:03



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해