PDA

View Full Version : Prevent switching between windows



maratk1n
10th April 2017, 15:39
Hi all!

I have two questions ...



Switching windows

I have a main window that never closes. Sometimes I open other windows on top of the main window.
I want the user to not be able to hide the top window by clicking on the area of the main window.
How I can prohibit the transition to another window?

Window cleaning

By opening additional windows, the user enters some parameters. On the form there are two buttons "Apply" and "Cancel". Each of them hides a window. But if you click "Cancel" and then open this window again, we will see the entered parameters that we canceled. I have to create slots for the buttons and there set the current parameters or clear the fields so that the next time I open the window, I see the valid values of the parameters. Can I somehow return the window back to the state of the class constructor in a different way?


Thanks all!:)

Lesiok
10th April 2017, 15:53
Show the code snippet where you create a new window. I think the problem is that using show() instead of exec().

maratk1n
10th April 2017, 16:02
Show the code snippet where you create a new window. I think the problem is that using show() instead of exec().

You're right.
I have a QDialog. I tried to change it to exec(), and it worked!:) But with QWidgets this does not work ...



//constructor MainWindow
settings = new COMSettings; //QDialog
passform = new PasswordForm(); //QWidget
initActionConnection();

//...//

void MainWindow::manualModeAction()
{
if (manualModeState)
{
QMessageBox reply;
reply.setStyleSheet("QLabel{min-width:500 px; min-height:150 px} QPushButton{ width:250px; min-height:50 px}");
reply.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
reply.setText("<p align='center'>Exit?</p>");
reply.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
if (reply.exec() == QMessageBox::Yes)
manualMode(false);
}
else
{
passform->show();
}

}
void MainWindow::initActionConnection()
{
connect(ui->manualModeButton, SIGNAL(clicked()), this, SLOT(manualModeAction()));
connect(ui->comSetButton, SIGNAL(clicked()), settings, SLOT(exec()));
}

Lesiok
10th April 2017, 17:18
1. Define PasswordForm as QDialog.
2. Don't create this objects in heap. Just use local object created on stack :
void MainWindow::manualModeAction()
{
if (manualModeState)
{
QMessageBox reply;
reply.setStyleSheet("QLabel{min-width:500 px; min-height:150 px} QPushButton{ width:250px; min-height:50 px}");
reply.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
reply.setText("<p align='center'>Exit?</p>");
reply.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
if (reply.exec() == QMessageBox::Yes)
manualMode(false);
}
else
{
PasswordForm passform;
if( passform.exec() == QDialog::Accepted )
{//do what You need on accept
}
else
{//do what You need on reject
}
}

}

maratk1n
11th April 2017, 12:01
1. Define PasswordForm as QDialog.
2. Don't create this objects in heap. Just use local object created on stack :


else
{
PasswordForm passform;
if( passform.exec() == QDialog::Accepted )
{//do what You need on accept
}
else
{//do what You need on reject
}
}

}

I'm sorry, but I did not understand this moment.
What means "//do what You need on accept", "//do what You need on reject"?
What will happen after this else? Will the class PasswordForm destructor be called?

P.S. Remade all windows to QDialog, now the first item works as it should. Thanks! :)

Lesiok
11th April 2017, 13:09
Dear friend, do not misunderstand me but it's time to come back to C++ basics. Qt is nothing else but C++.

maratk1n
14th August 2017, 20:20
Dear friend, do not misunderstand me but it's time to come back to C++ basics. Qt is nothing else but C++.

It was a stupid question, I'm sorry.:)
Objects created within a function are local. Therefore, they are destroyed after exiting the function ..
Thanks again for the advice