Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QDialog - Prevent Closing in Python and PyQt

Tags:

I have a login screen dialog written using pyqt and python and it shows a dialog pup up when it runs and you can type in a certin username and password to unlock it basicly. It's just something simple I made in learning pyqt. I'm trying to take and use it somewhere else but need to know if there is a way to prevent someone from using the x button and closing it i would like to also have it stay on top of all windows so it cant be moved out of the way? Is this possible? I did some research and couldn't find anything that could help me.

Edit:

as requested here is the 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' and
               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_())