0
votes

I open QDialog window from QMainWindow. Now when I press the QDialog window its not always closing in the first press - I need to press few times (3-4) to close it . I have closeEvent slot that has simple event->accept(); inside it.

This is how I call the QDialog from the main window:

void MyManager::DialogContainerOpen(type t)
{
 if(pMyDialogContainer == NULL)
 {
     pMyDialogContainer = new MyDialogContainer();
 }

 int returnVal = QDialog::Rejected;
 if(!m_bContainer)
 {
  m_bContainer = true;

  int returnVal = pMyDialogContainer->exec();


  if(returnVal != QDialog::Accepted ) {
   m_bContainer = false;
  }
 }
}

This is the first problem.

The second problem is how do i set the QDialog windows NOT to be allays on top? (I don’t want it to block the parent window.

UPDATE
well i found out that the function from the MainWindow that showing the contexMenu and inside it has the connect single/slot is keeps to invoke so i just used the disconnect i dont know if its the best sulotion but its working.
now i juat have the final problem . here is the code i hope its ok

void  MainWindowContainer::ShowContextMenu(const QPoint& pos) // this is a slot
{

    QModelIndex modelIndx;

    QPoint globalPos = ui.treeView_mainwindow->mapToGlobal(pos);


    bool b1 = connect(OpenAction, SIGNAL(triggered()),m_SignalMapper, SLOT(map()) );
    m_SignalMapper->setMapping(OpenAction,voidID);
    bool b2 = connect(m_SignalMapper, SIGNAL(mapped(QString)), this, SLOT(OpenWin(QString)));

    QAction* selectedItem = ContextMenu.exec(globalPos);

}


void MainWindowContainer::OpenWin(QString gid)
{
    //disconnect(sender0, SIGNAL(overflow()),receiver1, SLOT(handleMathError()));
    disconnect(m_SignalMapper, SIGNAL(mapped(QString)),this, SLOT(OpenWin(QString)));
    disconnect(OpenAction,SIGNAL(triggered()),m_SignalMapper, SLOT(map()));

 ....
 ....

}
1
What happens when you don't override closeEvent at all? (It's not a slot BTW.)Mat

1 Answers

1
votes

For your second question, the term you are looking for is modal vs modeless dialogs. The QDialog documentation tells exactly how you create non-modal dialogs:

Modeless dialogs are displayed using show(), which returns control to the caller immediately.

i.e. don't use exec() as that will make a modal dialog (which blocks the parent).

You should not connect the same signal/slot more than once unless you want the action run multiple times. All you need to do is to connect the QAction's signal to the slot once. This is usually done in the constructor (or a dedicated function called from the constructor) where you create the action.