Unsolved QPushbutton movable Dynamically
-
Hi,
I want to move qpushbutton to top position if my widget is resized dynamically, Please help me how to approach.
Thanks in advance.
-
Hi! See the following links for the building blocks:
-
Hi,
I went through the link, but I didn't how to approach my requirement.
I am having widget and some labels and buttons in that, so when i resize my widget with mouse dragging the buttons which are placed bottom of widget should move to top position. -
When you resize the window widgets, its resizeEvent function is called.
There you can move the button widget with move to where ever you want.Its unclear what top position is but if its another y position, then move should be fine.
-
Hi mrji,
How this resizeEvent is used? Can you please guide me?
Thanks in advance
-
Hi
You must subclass the widget and implement your own version
likevoid MYWidget::resizeEvent(QResizeEvent* event) { MYWidget::resizeEvent(event); // make sure to call base // Your code here. }
-
Hi,
I am using this resizeevent, but it is calling when binary runs.
void MainWindow::resizeEvent(QResizeEvent* event)
{
qDebug("ResizeEvent");
ui->pushButton->move(0,0);
QMainWindow::resizeEvent(event);
} -
hi
- but it is calling when binary runs.
Yes, is that not what you asked for ?
Events only works when app is running.Do you mean in Designer ?
-
Hi ,
No, it should called when user wil resize the gui using mouse.
-
Sorry i do not understand what is wrong.
The resizeEvent will be called when user resize the running app.
Are you talking about inside Designer part, where you do widget design or where do you mean?
is your widget a Designer plugin ?
-
Hi,
You have said when resize event is used, it calls when user resize the running app.
So I have done when user user resizes the app, then button have to move its Y axis, so i have written my code as follows:
void MainWindow::resizeEvent(QResizeEvent* event)
{
qDebug("ResizeEvent");
ui->pushButton->move(0,0);
QMainWindow::resizeEvent(event);
}But when my is running, without resizing app, button position is changing, my requirement is when user resizes app then only button position i.e, y-axis have to change, I hope you got my point
-
@Apeksha Why do you position the button manually? Why not just use layouts?
-
I am having some labels,lineedits and buttons in my gui, my requirement is when user resizes gui, then button have to change position.
-
@Apeksha
Ahhh, now i understand.
Well, there is no way to tell if done by system at start up or by the user.
But should it not do the same ?
Or only if size is smaller then the start size or ? what is the rule? -
Hi,
There is no way to do as per my requirement, when user resizes app, then button has to change its position. -
Hi
resizeEvent(event) is the way to do it.
You just need to make sure then you do not react to the first resize events you get when app starts up. -
Hi,
I am using resizeevent , but my button is moving initially when app runs, but it have to move when I resize my gui.
void MainWindow::resizeEvent(QResizeEvent* event)
{
qDebug("ResizeEvent");
ui->pushButton->move(0,0);
QMainWindow::resizeEvent(event);
}
this is the way I am doing, any correction? -
That is fine. but you will also do on first resize
to avoid that, make some if statements
the event has both oldSize and newSixe to checkI cannot tell you what to write as i dont know
what the rules are to move the button.
At what sizes etc.You can also use a timer to only allowed after say 10 secs to
avoid doing it on first resize. -
Hi,
k, Assume my gui isof width and height 500,500, its resized to 400,400 then button has to change position, can u share sample code, I am not getting how to make
-
@Apeksha Just add a boolean variable to your class and set it to false in the resizeEvent:
MainWindow::MainWindow(...): firstTime(true) { ... } void MainWindow::resizeEvent(QResizeEvent* event) { qDebug("ResizeEvent"); if (!firstTime) { ui->pushButton->move(0,0); } else { firstTime = false; } QMainWindow::resizeEvent(event); }