Results 1 to 7 of 7

Thread: Prevent switching between windows

  1. #1
    Join Date
    Apr 2017
    Posts
    30
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Smile Prevent switching between windows

    Hi all!

    I have two questions ...


    1. 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?
    2. 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!

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Prevent switching between windows

    Show the code snippet where you create a new window. I think the problem is that using show() instead of exec().

  3. The following user says thank you to Lesiok for this useful post:

    maratk1n (10th April 2017)

  4. #3
    Join Date
    Apr 2017
    Posts
    30
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Prevent switching between windows

    Quote Originally Posted by Lesiok View Post
    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 ...

    Qt Code:
    1. //constructor MainWindow
    2. settings = new COMSettings; //QDialog
    3. passform = new PasswordForm(); //QWidget
    4. initActionConnection();
    5.  
    6. //...//
    7.  
    8. void MainWindow::manualModeAction()
    9. {
    10. if (manualModeState)
    11. {
    12. QMessageBox reply;
    13. reply.setStyleSheet("QLabel{min-width:500 px; min-height:150 px} QPushButton{ width:250px; min-height:50 px}");
    14. reply.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    15. reply.setText("<p align='center'>Exit?</p>");
    16. reply.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    17. if (reply.exec() == QMessageBox::Yes)
    18. manualMode(false);
    19. }
    20. else
    21. {
    22. passform->show();
    23. }
    24.  
    25. }
    26. void MainWindow::initActionConnection()
    27. {
    28. connect(ui->manualModeButton, SIGNAL(clicked()), this, SLOT(manualModeAction()));
    29. connect(ui->comSetButton, SIGNAL(clicked()), settings, SLOT(exec()));
    30. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by maratk1n; 10th April 2017 at 15:06.

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Prevent switching between windows

    1. Define PasswordForm as QDialog.
    2. Don't create this objects in heap. Just use local object created on stack :
    Qt Code:
    1. void MainWindow::manualModeAction()
    2. {
    3. if (manualModeState)
    4. {
    5. QMessageBox reply;
    6. reply.setStyleSheet("QLabel{min-width:500 px; min-height:150 px} QPushButton{ width:250px; min-height:50 px}");
    7. reply.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    8. reply.setText("<p align='center'>Exit?</p>");
    9. reply.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    10. if (reply.exec() == QMessageBox::Yes)
    11. manualMode(false);
    12. }
    13. else
    14. {
    15. PasswordForm passform;
    16. if( passform.exec() == QDialog::Accepted )
    17. {//do what You need on accept
    18. }
    19. else
    20. {//do what You need on reject
    21. }
    22. }
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to Lesiok for this useful post:

    maratk1n (11th April 2017)

  7. #5
    Join Date
    Apr 2017
    Posts
    30
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Prevent switching between windows

    Quote Originally Posted by Lesiok View Post
    1. Define PasswordForm as QDialog.
    2. Don't create this objects in heap. Just use local object created on stack :
    Qt Code:
    1. else
    2. {
    3. PasswordForm passform;
    4. if( passform.exec() == QDialog::Accepted )
    5. {//do what You need on accept
    6. }
    7. else
    8. {//do what You need on reject
    9. }
    10. }
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    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!

  8. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Prevent switching between windows

    Dear friend, do not misunderstand me but it's time to come back to C++ basics. Qt is nothing else but C++.

  9. The following user says thank you to Lesiok for this useful post:

    maratk1n (11th April 2017)

  10. #7
    Join Date
    Apr 2017
    Posts
    30
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Prevent switching between windows

    Quote Originally Posted by Lesiok View Post
    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

Similar Threads

  1. Switching windows
    By Drama in forum Newbie
    Replies: 1
    Last Post: 21st January 2016, 17:21
  2. Replies: 1
    Last Post: 12th June 2014, 07:27
  3. Switching between two windows
    By Prasad_ in forum Newbie
    Replies: 1
    Last Post: 15th May 2013, 08:29
  4. Replies: 0
    Last Post: 23rd November 2011, 18:56
  5. Switching 5.2 from 5.0.2
    By baray98 in forum Qwt
    Replies: 1
    Last Post: 11th May 2009, 17:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.