1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
| # _*_ coding: utf-8 _*_ __author__ = '春江花月夜oo'
from PySide2.QtWidgets import QApplication, QMessageBox, QTableWidgetItem, QAbstractItemView, QPushButton, \ QGraphicsDropShadowEffect, QWidget, QListWidget, QLabel, QVBoxLayout, QListWidgetItem, QMainWindow, QLineEdit, \ QHBoxLayout, QTextEdit, QInputDialog, QRadioButton, QCheckBox from PySide2.QtUiTools import QUiLoader from PySide2.QtCore import QFile, Qt, QPoint, Slot, QThread, QObject, Signal from PySide2 import QtCore, QtGui from PySide2.QtGui import QPixmap, QPainter, QPainterPath, QCursor, QMouseEvent, QIcon from models import Users import requests import datetime import threading from zim import MyWindow, LiaoTian
class LoginWidget(QMainWindow): def __init__(self): super(LoginWidget, self).__init__() self._startPos = None self._endPos = None self._tracking = False self.resize(364, 284) self.setStyleSheet("background-color:white;border:0px") self.setWindowTitle('QQ登录') self.setWindowIcon(QIcon('imgs/qie.png')) self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.WindowMinMaxButtonsHint)
self.b2 = QPushButton(self) self.b2.setGeometry(347, 0, 15, 15) self.b2.setStyleSheet("QPushButton{color:black}" "QPushButton:hover{color:red}" "QPushButton{background-color: none}" "QPushButton{border:none}" "QPushButton{border-radius:10px}" "QPushButton{padding:2px 4px}") self.b2.setIcon(QIcon("imgs/close.gif"))
self.b3 = QPushButton(self) self.b3.setGeometry(327, 0, 15, 15) self.b3.setStyleSheet("QPushButton{color:black}" "QPushButton:hover{color:red}" "QPushButton{background-color: none}" "QPushButton{border:none}" "QPushButton{border-radius:10px}" "QPushButton{padding:2px 4px}" )
self.b3.setIcon(QIcon("imgs/maxize2.png")) self.b4 = QPushButton(self) self.b4.setGeometry(307, 0, 15, 15) self.b4.setStyleSheet("QPushButton{color:black}" "QPushButton:hover{color:red}" "QPushButton{background-color: none}" "QPushButton{border:none}") self.b4.setIcon(QIcon("imgs/minixize7.png")) self.b2.clicked.connect(self.exit_b2) self.b3.clicked.connect(self.max_b3_0) self.b4.clicked.connect(self.minix_b4)
self.le1 = QLineEdit(self) self.le1.setGeometry(100, 160, 160, 25) self.le1.setStyleSheet('border: 1px solid gray; border-bottom: none; color:black; font-family:黑体') self.le1.setPlaceholderText('QQ号码/手机/邮箱') self.le1.show() self.le2 = QLineEdit(self) self.le2.setGeometry(100, 185, 160, 25) self.le2.setStyleSheet('border: 1px solid gray; color:black; font-family:黑体') self.le2.setEchoMode(QLineEdit.Password) self.le2.setPlaceholderText('密码') self.le2.show() self.b5 = QCheckBox(self) self.b5.setGeometry(100, 212, 20, 20)
self.b6 = QCheckBox(self) self.b6.setGeometry(196, 212, 20, 20)
self.b6.setStyleSheet('') self.l2 = QLabel(self) self.l2.setGeometry(119, 214, 50, 15) self.l2.setText('记住密码') self.l2.setStyleSheet('color: grey; font-family: 黑体') self.l3 = QLabel(self) self.l3.setGeometry(215, 214, 50, 15) self.l3.setText('自动登录') self.l3.setStyleSheet('color: grey; font-family: 黑体') self.l4 = QLabel(self) self.l4.setStyleSheet("background:none; color:white; ") pixmapa = QPixmap("imgs/qie.png") pixmap = QPixmap(100, 100) pixmap.fill(Qt.transparent) painter = QPainter(pixmap) painter.begin(self) # 要将绘制过程用begin(self)和end()包起来 painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) # 一个是平滑,一个是缩放保持比例 path = QPainterPath() path.addRect(0, 0, 100, 100) painter.setClipPath(path) painter.drawPixmap(0, 0, 100, 100, pixmapa) painter.end() self.l4.setPixmap(pixmap) self.l4.setScaledContents(True) self.l4.setGeometry(30, 160, 70, 70)
self.l5 = QLabel(self) self.l5.setStyleSheet("background:none; color:white; ") pixmapa = QPixmap("imgs/qqbackground.jpg") pixmap = QPixmap(100, 100) pixmap.fill(Qt.transparent) painter = QPainter(pixmap) painter.begin(self) # 要将绘制过程用begin(self)和end()包起来 painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) # 一个是平滑,一个是缩放保持比例 path = QPainterPath() path.addRect(0, 0, 100, 100) painter.setClipPath(path) painter.drawPixmap(0, 0, 100, 100, pixmapa) painter.end() self.l5.setPixmap(pixmap) self.l5.setScaledContents(True) self.l5.setGeometry(0, 0, 380, 150) self.b2.raise_() self.b3.raise_() self.b4.raise_()
self.l6 = QLabel(self) self.l6.setGeometry(265, 165, 50, 15) self.l6.setText('注册账号') self.l6.setStyleSheet('color: blue') self.l7 = QLabel(self) self.l7.setGeometry(265, 190, 50, 15) self.l7.setText('找回密码') self.l7.setStyleSheet('color: blue')
self.b7 = QPushButton(self) self.b7.setGeometry(100, 240, 160, 30) self.b7.setStyleSheet('background: rgb(147, 125, 255); color:white') self.b7.setText('登录') self.b7.clicked.connect(self.login_b7)
def minix_b4(self): self.showMinimized()
def max_b3_0(self): self.showMaximized() self.b3.clicked.disconnect() self.b3.clicked.connect(self.max_b3_1) self.b3.setIcon(QIcon("imgs/minixize8.png"))
def max_b3_1(self): self.showNormal() self.b3.clicked.disconnect() self.b3.clicked.connect(self.max_b3_0) self.b3.setIcon(QIcon("imgs/maxize2.png"))
def exit_b2(self): self.close()
def login_b7(self): uid = self.le1.text() password = self.le2.text() from models import conn result = conn.query(Users).filter(Users.uid == uid, Users.password == password).all() if result: self.hide() myWindow = MyWindow(result[0]) myWindow.show() else: qm =QMessageBox() qm.setWindowIcon(QIcon('imgs/qie.png')) qm.addButton('确定', QMessageBox.YesRole) qm.information(self, "提示", "用户不存在或密码错误") print('cccccccccccccccccccccccccuole')
def mouseMoveEvent(self, e: QMouseEvent): # 重写移动事件 if self._tracking: self._endPos = e.pos() - self._startPos self.move(self.pos() + self._endPos)
def mousePressEvent(self, e: QMouseEvent): if e.button() == Qt.LeftButton: self._startPos = QPoint(e.x(), e.y()) self._tracking = True
def mouseReleaseEvent(self, e: QMouseEvent): if e.button() == Qt.LeftButton: self._tracking = False self._startPos = None self._endPos = None
def keyPressEvent(self, event): if event.key() == Qt.Key_Return: self.login_b7()
if __name__ == '__main__': app = QApplication([]) run = LoginWidget() run.show() app.exec_()
|