QDialog - Prevent Closing in Python and PyQt -
i have login screen dialog written using pyqt , python , shows dialog pup when runs , can type in certin username , password unlock basicly. it's simple made in learning pyqt. i'm trying take , use somewhere else need know if there way prevent using x button , closing have stay on top of windows cant moved out of way? possible? did research , couldn't find me.
edit:
as requested here code:
from pyqt4 import qtgui class test(qtgui.qdialog): def __init__(self): qtgui.qdialog.__init__(self) self.textusername = qtgui.qlineedit(self) self.textpassword = qtgui.qlineedit(self) self.loginbuton = qtgui.qpushbutton('test login', self) self.loginbuton.clicked.connect(self.login) layout = qtgui.qvboxlayout(self) layout.addwidget(self.textusername) layout.addwidget(self.textpassword) layout.addwidget(self.loginbuton) def login(self): if (self.textusername.text() == 'test' , self.textpassword.text() == 'password'): self.accept() else: qtgui.qmessagebox.warning( self, 'wrong', 'incorrect user or password') class window(qtgui.qmainwindow): def __init__(self): qtgui.qmainwindow.__init__(self) if __name__ == '__main__': import sys app = qtgui.qapplication(sys.argv) if test().exec_() == qtgui.qdialog.accepted: window = window() window.show() sys.exit(app.exec_())
bad news first, not possible remove close button window, based on riverbank mailing system
you can't remove/disable close button because handled window manager, qt can't there.
good news, can override , ignore, when user sends event, can ignore or put message or something.
read article ignoring qcloseevent
also, take @ question, how catch pyqt closeevent , minimize dialog instead of exiting?
which uses this:
class mydialog(qtgui.qdialog): # ... def __init__(self, parent=none): super(mydialog, self).__init__(parent) # when want destroy dialog set true self._want_to_close = false def closeevent(self, evnt): if self._want_to_close: super(mydialog, self).closeevent(evnt) else: evnt.ignore() self.setwindowstate(qtcore.qt.windowminimized)
Comments
Post a Comment