![]() |
Draggable rectangle in both screen orientations
I have a draggable rectangle on a page. I would like to drag the rectangle around the screen area in both portrait and landscape and not allow it to go off screen.
Currently, I have my draggable rectangle working in portrait mode, now how do I achieve this in landscape mode?, when I turn the phone, the rectangle is often 'off screen' either totally or a just a little, so how do I keep it on screen in landscape orientation as well as portrait? Clearly, I want to keep my rectangle as draggable in both screen orientations, so the rectangle cannot be anchored...or can it?, I have tried with different positioning methods, but all prevent my rectangle from being draggable. It would also be nice if my rectangle could have a 'starting' position, like screen center, but again, all attempts have failed because I want to keep the rectangle, draggable. Currently, the rectangle appears at the top left of my screen in portrait. I looked at an app from coderus, that being ScreenTapShot2, for some 'mouse trick' clues, but I am still none the wiser, any ideas/input appreciated. |
Re: Draggable rectangle in both screen orientations
Normally, when you are within a Page (and within an ApplicationWindow), this should handle orientation aspects for you and you could handle things via width and height (or isPortrait) of the page.
I'd try making a small check onIsPortraitChanged or something: if element.x + element.width > page.width then make element.x = page.width - element.width then do the same with y and height. Anchoring only makes sense if you have other elements to anchor on, which wouldn't be the case for what I'm understanding of your problem. I hope this gives you the right impulse… :) edit: To give it a starting position, you could just set x and y in the qml which you most likely overwrite on drag… for example x: page.width - width/2 edit2: perhaps it's easiest if you study http://doc.qt.io/qt-5/qml-qtquick-mo....maximumX-prop – so you won't need to reimplement stuff that's already available. |
Re: Draggable rectangle in both screen orientations
One problem sorted!, here's how.....
Draggable rectangle can be anchored and still be dragged when 'onPressed'; Example: Code:
Rectangle { |
Re: Draggable rectangle in both screen orientations
show full code please -_-
|
Re: Draggable rectangle in both screen orientations
Quote:
Code:
Item { |
Re: Draggable rectangle in both screen orientations
I'd really recommend using the pages dimensions as a base instead of just trying hardcoded values – to make it useable on other screens/devices.
But then again probably I'm not getting what you're trying to do. :) |
Re: Draggable rectangle in both screen orientations
I think you are right@velox, I hadn't disregarded your comments about pages dimensions and my few attempts have failed. But, I will keep trying but bear with me, I don't have use of QtCreator or SFOS sdk (couldn't get either to work), so I am doing this on my phone via ssh from PC.......hit and miss programming I believe coderus called it, lol....and he's right!
Anyway, the premise is, although not the full story; I simply want a draggable rectangle to keep within screen bounds in either orientation (portrait and landscape). Thank you for your input :) |
Re: Draggable rectangle in both screen orientations
Quote:
If I get you right: Code:
import QtQuick 2.0 |
Re: Draggable rectangle in both screen orientations
Quote:
Otherwise, thank you for the code!, I will now have another crack at it! :) |
Re: Draggable rectangle in both screen orientations
Code:
import QtQuick 2.0 The reason I had 'Drag.active: dragArea.drag.active' is because I'm working on the lockscreen, which of course has its own movement, enabling Drag.active, means I can move the rectangle around the screen without moving the lockscreen..... |
All times are GMT. The time now is 23:00. |
vBulletin® Version 3.8.8