I need to open a new window from my applications main window. This new window need to be
modal, I need to be able to get a result from the modal window based on user interaction with it.
I have figured out how to make the window modal. But I can't figure out how to return a result from the modal window and pass it back to the main window when user close the modal window.
You probably want to make your window a gtk.Dialog and launch it via the run() method. This is designed to do exactly what you are looking for.
See pygtk docs for gtk.Dialog.run
Related
I want to make a pop up window that requires the user to interact with before using the main window, Modal Dialog. For example, the messagebox requires the user to answer the question before moving on. If the user tries to click on the original window, the messagebox flashes and plays the iconic error sound. This is what I want; I would use a messagebox but I want to add buttons, labels, widgets, etc...
How do you make a pop up window Modal Dialog?
So I have a script running inside another program (The Foundry's Hiero) and I'm just making a new QWidget object, and calling self.show()
Now, I can set it to self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint), so my window will stay on top of the main window, even if you click on something in the main window.
The problem is, this is a sort of popup window that you configure settings in, and it triggers other QWidget popups. If I set my window to WindowStaysOnTopHint, those subdialogs that my widget triggers end up beneath my widget.
Is there a way in PySide/PyQt to make a window stay on top/keep focus from the main application window in particular, but not everything?
You can use the QApplication.focusChanged signal to raise your widget up when Hiero's main window is selected. Then you would just need to remove the WindowStaysOnTopHint flag.
I'm not familiar with Hiero's API, but I'm guessing you could try something like:
def raiseMyWidget(old, new):
if new == hiero.ui.mainWindow():
myWidget.raise_()
QtWidgets.QApplication.instance().focusChanged.connect(raiseMyWidget)
Hope this helps! You can take advantage of the old parameter or some other means to make sure that your widget isn't raised above the others as well.
I'm making a GUI using pyqt5 and I have two windows. In the first window, there is a button to open the second window. Now, I want to prevent windows switching from the second window to the first one. For example, when we open file dialog, we cannot switch to the main window and the main window is not clickable. (you can check it)
I have tried to set windows flag with :
setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
but it just makes the second window stay on top and I can still switch to the first window. Is there a way to prevent windows switching or make the first window to be not clickable?
Thanks in advance
You can make the window modal by:
setWindowModality(Qt.ApplicationModal)
I want to make a new PyQt window show up and hide the current window when I click a button. After playing around for hours, I haven't found a good way to do this.
When I try to show a new QDialog and hide the current one, the program closes. It works if another window is open. I believe this is because it is viewing the last window as closing and terminates, or maybe the new QDialog is falling off the stack.
My current method involves storing the QDialog as a variable in the current dialog, then showing it and hiding current dialog. This seems like a total hack, though.
Example below:
def _createQuestion(self):
# initialization of the UI and everything goes on in the constructor
self.dialog = QuestionBanks()
self.dialog.show()
self.hide()
Is there a better way of switching a single window to a distinct different single window in PyQt4?
I have a ctrl+f dialog and when I press the window, it causes the main window to lose focus. Is there a way to have both windows have focus?
Kind of, but not really. Only one window can claim focus on the desktop/operating system level. You want this to be your application or main PyQT object. Then, what you want to do is define a new window type (QObject) that will be treated like a toolbox/dialog within the parent application. This will set a child-like focus attribute. Your application will retain focus on the desktop level, and now you have another inner-focus attribute for windows spawned from within your app.
QtGui QStyleOptionToolBox
StackOverflow: pyqt popup window