Qt- how to move a picture in screen according to mouse move
By : Arthur Venturin
Date : March 29 2020, 07:55 AM
I wish this help you Have a look at QGraphicsView, it gives you a canvas to put items on, and even can do animations. Should make things a lot easier than painting pixmaps by hand.
|
How does one align views at certain positions of the screen, staying consistent across multiple screen resolutions?
By : Jenny Brito
Date : March 29 2020, 07:55 AM
Hope this helps I have found a solution! One that is completely relative to itself, and does not rely on pixels or density pixels at all. I've placed a TextView of 0x0 in the middle of the screen, and put RelativeLayouts on top of and below it, filling the screen. code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mainbg">
<TextView
android:text=" "
android:id="@+id/ankermidden"
android:layout_centerVertical="true"
android:layout_width="0dp"
android:layout_height="0dp">
</TextView>
<RelativeLayout
android:id="@+id/ankerveldboven"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/ankermidden">
<TextView
android:text=" "
android:id="@+id/ankerboven"
android:layout_centerVertical="true"
android:layout_width="0dp"
android:layout_height="0dp">
</TextView>
<RelativeLayout
android:id="@+id/ankerveldmidboven"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/ankerboven">
<Button
android:text="@string/topbutton"
android:background="@drawable/silvertablesbuttonbgkort"
android:id="@+id/topbutton"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center|center_vertical">
</Button>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/ankerveldonder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/ankermidden">
<TextView
android:text=" "
android:id="@+id/ankeronder"
android:layout_centerVertical="true"
android:layout_width="0dp"
android:layout_height="0dp">
</TextView>
<RelativeLayout
android:id="@+id/ankerveldmidonder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/ankeronder">
<Button
android:text="@string/midbutton"
android:background="@drawable/silvertablesbuttonbglang"
android:id="@+id/midbutton"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center|center_vertical">
</Button>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/underbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:text="@string/underbartekst"
android:background="@drawable/silvertablesunderbar"
android:id="@+id/underbarbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:textSize="20dp"
android:gravity="left|center_vertical" >
</Button>
</RelativeLayout>
|
How can I move my picture on the screen using a keypress?
By : biggboss10
Date : March 29 2020, 07:55 AM
seems to work fine What is missing here, is the position at which you draw the house. Let's change the drawing function accordingly: code :
void draw(int h, int v, int j)
{
cout << string(v, '\n'); //vertical offset
string hs(h,' '); // prepare horizontal offset
cout <<hs<< " /"; // add horizontal offset at each start of line
for (int c = 0; c<j; c++) {
cout << " ";
}
...
}
void Move(int key, int& h, int& v, int housesize)
{
if (key == 'a') { // would worth considering tolower(key)
if (h>1)
h--;
}
else if (key == 's') {
h++; // is there a maximum (e.g. screensize - housewidth) ?
}
else if (key == 'd') {
v++;
}
else if (key == 'w') {
if (v>1)
v--;
}
}
int h = 0, v = 0; // horizontal and vertical offset
...
while (1) {
letter = getch();
...
else if (number != 27) {
Move(number, h, v, i); // <=== just change position. Will redraw later
}
ClearScreen();
draw(h, v, i); // draw at new position what ever happened
}
|
How can I move(translate) picture randomly, any position of the screen?
By : user3242448
Date : March 29 2020, 07:55 AM
hop of those help? I want to translate image to any position in the screen? what should I do? , Personally I think CGAffineTransform is the way to go. code :
@objc func updatePosition() {
let maxX = view.frame.maxX - imageViewWidth
let maxY = view.frame.maxY - imageViewHeight
let xCoord = CGFloat.random(in: 0...maxX)
let yCoord = CGFloat.random(in: 0...maxY)
UIView.animate(withDuration: 0.3) {
imageView.transform = CGAffineTransform(translationX: xCoord, y: yCoord)
}
}
|
How to make picture box move across screen
By : GiapLv
Date : March 29 2020, 07:55 AM
it should still fix some issue Well, picture is a local variable and thus is not visible outside Button1_Click. Let's turn it into a field: code :
// now picture is a private field, visible within th class
//TODO: do not forget to Dispose it
private PictureBox picture;
private void Button1_Click(object sender, EventArgs e)
{
if (picture != null) // already created
return;
picture = new PictureBox
{
Name = "pictureBox",
Size = new Size(20, 20),
Location = new System.Drawing.Point(x, y),
Image = image1,
Parent = this, // instead of this.Controls.Add(picture);
};
timer1.Enabled = true;
}
private void Timer1_Tick(object sender, EventArgs e)
{
//redefine pictureBox position.
x = x - 50;
if (picture != null) // if created, move it
picture.Location = new System.Drawing.Point(x, y);
}
|