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()));....
....}@
-
[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.
-
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.
-
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.
-
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.