Problem with QDialog , its not closeing right away when pressing the x , how to make it NOT on top?



  • Hello all
    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 what 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()));

    ....
    ....

    }@



  • There's a difference between event->accept() and this->accept() the former will prevent it from actually closing. exec() will always block the parent window. You'll have to use show() and signal/slots instead.



  • what do you mean loladiro ? can you give short example please



  • It's all explained in the [[Doc:QDialog]] API docs, including examples (look for the modal/modeless explanations), did you check those already?



  • Ok Thanks about the modeless problem i understood .
    what about the connect / disconnect problem am i doing it right



  • [quote author="umen242" date="1312788672"]Ok Thanks about the modeless problem i understood .
    what about the connect / disconnect problem am i doing it right [/quote]

    Probably not. The code looks a bit weird to me. But it's hard to analyze without the complete classes and without knowing what you actually want to do.



  • what do you what me to show you , its context menu (right click ) when im on tree node it give me the option to right click and opem QDialog window



  • So, why do you double the functionality? The signal mapper is only needed if the context menu needs to stay open during the execution of the slot called from the mapper.

    The menu exec gives you back the selected menu entry:

    @
    QAction* selectedItem = ContextMenu.exec(globalPos);
    @

    Just call the appropriate dialog according to the action returned by exec and abandon the QSignalMapper completely.



  • im using the mapper to pass value to OpenWin slot when triggered() signal is invoked
    i don't see any other option



  • Try this:

    @
    void MainWindowContainer::ShowContextMenu(const QPoint& pos) // this is a slot
    {
    QPoint globalPos = ui.treeView_mainwindow->mapToGlobal(pos);
    QAction* selectedItem = ContextMenu.exec(globalPos);

    if(selectedItem == OpenAction) {
        // do the open stuff
    } else if(selectedItem == EditAction) {
        // do the edit stuff
    }
    

    }
    @

    Problem with your approach is, that the actions fire while the menu is open - and during this time, the menu's event loop (call of exec) is still running and may interfere with the rest of the application.



  • Thanks Allot for your time to answer.
    but what if i have only one Action in the Context menu , and the action will be by the parameter taken from the node it stand on



  • Then you will have some code that attaches the data to the action anyways.

    You could consider "dynamic properties":http://doc.qt.nokia.com/4.7/qobject.html#dynamic-properties attached to your QAction instances. You can read those from the returned QAction.



  • ok i will check it out ,thanks again


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.