Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

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

    General and Desktop
    3
    13
    3412
    Loading More Posts
    • 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
      umen242 last edited by

      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 Reply Quote 0
      • L
        loladiro last edited by

        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 Reply Quote 0
        • U
          umen242 last edited by

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

          1 Reply Last reply Reply Quote 0
          • G
            goetz last edited by

            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 Reply Quote 0
            • U
              umen242 last edited by

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

              1 Reply Last reply Reply Quote 0
              • G
                goetz last edited by

                [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 Reply Quote 0
                • U
                  umen242 last edited by

                  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 Reply Quote 0
                  • G
                    goetz last edited by

                    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 Reply Quote 0
                    • U
                      umen242 last edited by

                      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 Reply Quote 0
                      • G
                        goetz last edited by

                        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 Reply Quote 0
                        • U
                          umen242 last edited by

                          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 Reply Quote 0
                          • G
                            goetz last edited by

                            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 Reply Quote 0
                            • U
                              umen242 last edited by

                              ok i will check it out ,thanks again

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post