I may have found the solution to my own question but I have another problem. It turns out that the user can just hit "Esc" and close the form. How can I disable the escape key? I'm looking for some python code, but I'm at a loss.
Edit
Below is my code, if it helps.
# -*- coding: iso-8859-15 -*-
from PyQt4 import QtCore, QtGui
import psycopg2
import hashlib
def authentication():
conn_string = "host='host' dbname='dbname' user='username' password=pass"
conn = psycopg2.connect(conn_string)
global userText
username = str(userText.text())
global passText
hashpassword = hashlib.md5(str(passText.text())).hexdigest()
cursor = conn.cursor()
cursor.execute('SELECT * FROM users WHERE username=%s AND password=%s', (username, hashpassword))
if cursor.rowcount == 1:
cursor.close ()
conn.close ()
global myDialog
myDialog.accept()
else:
cursor.close ()
conn.close ()
msgBox = QtGui.QMessageBox()
msgBox.setWindowTitle(QtGui.QApplication.translate("loginform", "Σφάλμα", None, QtGui.QApplication.UnicodeUTF8))
msgBox.setText(QtGui.QApplication.translate("msgBox", "Λάθος Όνομα Χρήστη ή Συνθηματικό", None, QtGui.QApplication.UnicodeUTF8))
msgBox.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint);
msgBox.exec_()
class Login (QtGui.QDialog):
dlg = QtGui.QDialog()
dlg.setObjectName("loginform")
dlg.setWindowTitle(QtGui.QApplication.translate("dlg", "Φόρμα σύνδεσης", None, QtGui.QApplication.UnicodeUTF8))
dlg.setEnabled(True)
dlg.resize(400, 203)
dlg.setMaximumSize(QtCore.QSize(400, 203))
dlg.setSizeGripEnabled(False)
dlg.setModal(True)
dlg.setWindowFlags(QtCore.Qt.FramelessWindowHint);
event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Escape, QtCore.Qt.NoModifier)
font = QtGui.QFont()
font.setPointSize(10)
username = QtGui.QLineEdit(dlg)
username.setEnabled(True)
username.setGeometry(QtCore.QRect(190, 19, 151, 21))
username.setFont(font)
username.setObjectName("username")
global userText
userText = username
userlabel = QtGui.QLabel(dlg)
userlabel.setEnabled(True)
userlabel.setGeometry(QtCore.QRect(70, 20, 91, 16))
userlabel.setFont(font)
userlabel.setLayoutDirection(QtCore.Qt.LeftToRight)
userlabel.setObjectName("userlabel")
userlabel.setText(QtGui.QApplication.translate("dlg", "Όνομα Χρήστη", None, QtGui.QApplication.UnicodeUTF8))
userlabel.setBuddy(username)
password = QtGui.QLineEdit(dlg)
password.setGeometry(QtCore.QRect(190, 59, 151, 21))
password.setFont(font)
password.setEchoMode(QtGui.QLineEdit.Password)
password.setPlaceholderText("")
password.setObjectName("password")
global passText
passText = password
passlabel = QtGui.QLabel(dlg)
passlabel.setGeometry(QtCore.QRect(70, 60, 91, 16))
passlabel.setFont(font)
passlabel.setMargin(0)
passlabel.setObjectName("passlabel")
passlabel.setText(QtGui.QApplication.translate("loginform", "Συνθηματικό", None, QtGui.QApplication.UnicodeUTF8))
passlabel.setBuddy(password)
btnLogin = QtGui.QPushButton(dlg)
btnLogin.setGeometry(QtCore.QRect(160, 170, 75, 23))
btnLogin.setDefault(False)
btnLogin.setFlat(False)
btnLogin.setObjectName("btnLogin")
btnLogin.setText(QtGui.QApplication.translate("loginform", "Σύνδεση", None, QtGui.QApplication.UnicodeUTF8))
btnLogin.clicked.connect(authentication)
global myDialog
myDialog = dlg
def keyPressEvent(self, event):
msg = QtGui.QMessageBox()
msg.setText("You Pressed: "+ event.text())
msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint);
msg.exec_()
dlg.show()
return
inauthentication
and it will bypass.