QPushbutton movable Dynamically
-
@jsulm said in QPushbutton movable Dynamically:
@Apeksha I still don't understand why you position this button manually...
I second that. I'm so curious, pretty please with sugar on top, explain your use case.
-
@Wieland
ui->contentWidget->setStyleSheet("QWidget {background-color:#C0C0C0;}");
ui->contentWidget->setMinimumSize( 820, 150 );
QHBoxLayout *ConfigurationLayout = new QHBoxLayout;
QScrollArea *scrollArea = new QScrollArea;
// scrollArea->setStyleSheet("QScrollArea {background-color:#C0C0C0;}");
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setWidget(ui->contentWidget);
scrollArea->setWidgetResizable(true);
ConfigurationLayout->addWidget(scrollArea);
mainBoxLayout->addLayout(ConfigurationLayout);This is my part of code where button movable is required, I had widget and scrollArea and some buttons.
So when my app is minimized, one of the button position should change, when gui is minized it have to display on top of widget. I hope you got my requirement. -
ok didnt check it lately , i assume its because the NewSize from event has not yep been applied.
I think i get your use case now
the button show sort of go to next col if there is no room to be below.
So its not on top of the other but on top in new col?
like this
-
@Apeksha
you can use
const QSize &QResizeEvent::oldSize() const
const QSize &QResizeEvent::size() const
to check what size window has and had.Based on those numbers , you can do the right thing, store button pos
or to restore the button to old pos.you can use qDebug() << "size" << event.oldSize() << " to " << event.Size();
to get an idea of what numbers you will see.
You can use
http://doc.qt.io/qt-5/qdesktopwidget.html#availableGeometryto get how big screen is.
-
I have used the same, but it's not working.
void MainWindow::resizeEvent(QResizeEvent* event)
{
qDebug() << "old size" << event->oldSize() << " to " << event->size();
int oldx,oldy;
oldpos=ui->pushButton->geometry();
oldx=oldpos.x();
oldy=oldpos.y();
qDebug()<<"oldpos x is"<<oldx<<"oldpos y is:"<<oldy;
if (!firstTime) {
ui->pushButton->move(50,100);
}else { ui->pushButton->move(oldx,oldy); firstTime = false; } QMainWindow::resizeEvent(event);
}
-
void MainWindow::resizeEvent(QResizeEvent* event)
{
qDebug() << "old size" << event->oldSize() << " to " << event->size();
int oldx,oldy;
oldpos=ui->pushButton->geometry();
oldx=oldpos.x();
oldy=oldpos.y();
qDebug()<<"oldpos x is"<<oldx<<"oldpos y is:"<<oldy;
if (!firstTime) {
ui->pushButton->move(50,100);
}else { ui->pushButton->move(oldx,oldy); firstTime = false; } QMainWindow::resizeEvent(event);
}
-
K i uderstood , Initially I will save oldx and oldy in constructor and where actually i have to use this oldx and oldy to restore. In above code If I use this oldx and oldy , its not restoring. I am attaching code:
void MainWindow::resizeEvent(QResizeEvent* event)
{
if (!firstTime) {
ui->pushButton->move(50,100);
}else { ui->pushButton->move(oldx,oldy); ---->This oldx and oldy Iam storing in constructor. firstTime = false; } QMainWindow::resizeEvent(event);
}
-
I think, Problem seems to be with enabling of flag "firsttime".
CAN YOU TRY THIS?
int oldX,oldY,fstFlag=1;
void MainWindow::resizeEvent(QResizeEvent *event)
{
if(!fstFlag)
{
oldX=0;
oldY=0;
fstFlag=1;
}
else
{
fstFlag=0;
oldX=50;
oldY=100;
}
ui->pushbutton->move(oldX,oldY);
}