On click new QDailog window overlaps with old window and everything becomes very messy , focus still remain on old window

StackOverflow https://stackoverflow.com/questions/20285549

  •  06-08-2022
  •  | 
  •  

Frage

Overview:
I have designed QPushbutton in some window which when clicked open a new Dialog Window( Say start_backup_window) .
In this window I have Designed another QPushbutton say check_backup_option_button which when clicked should open another Dialog window say ( backup_options_window).

Problem : Everything works as expected but when I click check_backup_option_button the new backup_options_window overlaps with previous start_backup_window. I have tried few things but it doesn't work.

Also I have noticed that when I drag old window the new window allows me to do so. Generally it happens that you cant do any thing to old window unless and util you click cancel or ok button in new window. May you guys please advice me how to proceed.

Below are my code

    start_backup_window_old.cpp


#include "backup_options_window.h" 

//  called init() function in the constructor

 start_backup_window::start_backup_window(QWidget *parent)
    : QDialog(parent), self_backup_options( 0 )
{
    ui.setupUi(this);
    init_cal_signals();
}


void start_backup_window::init_cal_signals()
{

connect( ui.check_backup_option_button, SIGNAL( clicked () ), this , SLOT( open_new_backup_options_window() ) );

}


void start_backup_window::open_new_backup_options_window()
{
    self_backup_options = new backup_options_window( this ); 
    self_backup_options->show();

}
War es hilfreich?

Lösung

The problem seem to be in setting the parent to the backup_options_window. I suggest to change the code in the following way:

void start_backup_window::open_new_backup_options_window()
{
    if (!self_backup_options)
        self_backup_options = new backup_options_window; 
    self_backup_options->setWindowModality(Qt::WindowModal); // makes the window modal
    self_backup_options->show();
}

With this implementation, you will need to delete self_backup_options pointer later. For example in destructor of start_backup_window class. Please don't forget to initialize the self_backup_options to null in the constructor of start_backup_window class.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top