Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QDialog , its not closeing right away when pressing the x , how to make it NOT on top?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 4.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    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()));

    ....
    ....

    }@

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

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

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • U Offline
            U Offline
            umen242
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              [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.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • U Offline
                U Offline
                umen242
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  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.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    umen242
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #10

                      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.

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • U Offline
                        U Offline
                        umen242
                        wrote on last edited by
                        #11

                        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

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #12

                          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.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • U Offline
                            U Offline
                            umen242
                            wrote on last edited by
                            #13

                            ok i will check it out ,thanks again

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved