2022-04-01 22:25:19 +08:00
|
|
|
import os
|
2022-04-04 22:34:07 +08:00
|
|
|
import string
|
2022-04-01 22:25:19 +08:00
|
|
|
import sys
|
2022-04-04 22:34:07 +08:00
|
|
|
from random import randint, choice
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
|
|
from PyQt5.QtWidgets import *
|
|
|
|
from PyQt5.QtGui import *
|
|
|
|
from utils.QSSLoader import QSSLoader
|
2022-04-04 22:34:07 +08:00
|
|
|
from PyQt5.QtCore import Qt, pyqtSignal
|
|
|
|
|
|
|
|
|
|
|
|
# def get_icon():
|
|
|
|
# # 测试模拟图标
|
|
|
|
# pixmap = QPixmap(16, 16)
|
|
|
|
# pixmap.fill(Qt.transparent)
|
|
|
|
# painter = QPainter()
|
|
|
|
# painter.begin(pixmap)
|
|
|
|
# painter.setFont(QFont('Webdings', 11))
|
|
|
|
# painter.setPen(Qt.GlobalColor(randint(4, 18)))
|
|
|
|
# painter.drawText(0, 0, 16, 16, Qt.AlignCenter,
|
|
|
|
# choice(string.ascii_letters))
|
|
|
|
# painter.end()
|
|
|
|
# return QIcon(pixmap)
|
|
|
|
|
|
|
|
|
|
|
|
def about_qt():
|
|
|
|
# 关于Qt
|
|
|
|
QApplication.instance().aboutQt()
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
class User(QLabel):
|
2022-04-04 22:34:07 +08:00
|
|
|
# 自定义信号, 注意信号必须为类属性
|
|
|
|
# button_clicked_signal = pyqtSignal()
|
|
|
|
|
2022-04-01 22:25:19 +08:00
|
|
|
def __init__(self):
|
|
|
|
super(User, self).__init__()
|
|
|
|
self.widget = QWidget(self)
|
2022-04-04 22:34:07 +08:00
|
|
|
self.widget.setMaximumWidth(300)
|
|
|
|
# self.resize(200, 60)
|
|
|
|
self.setObjectName('User')
|
2022-04-01 22:25:19 +08:00
|
|
|
# todo
|
|
|
|
# 修改布局使适合微软todo的样式
|
|
|
|
# 设置点击事件,使用右键菜单的样式添加设置、同步、退出
|
|
|
|
# 暂时就这样
|
|
|
|
layout = QHBoxLayout()
|
|
|
|
info_layout = QVBoxLayout()
|
|
|
|
self.pic_label = QLabel('')
|
2022-04-04 22:34:07 +08:00
|
|
|
self.pic_label.setObjectName('pic_label')
|
2022-04-01 22:25:19 +08:00
|
|
|
self.pic_label.setPixmap(
|
|
|
|
QPixmap(os.path.abspath('../') + '/images/user.svg').scaled(50, 50, Qt.IgnoreAspectRatio,
|
|
|
|
Qt.SmoothTransformation))
|
2022-04-04 22:34:07 +08:00
|
|
|
layout.addWidget(self.pic_label, 2)
|
|
|
|
# layout.addStretch(2)
|
2022-04-01 22:25:19 +08:00
|
|
|
self.user_name = QLabel("用户登录")
|
2022-04-04 22:34:07 +08:00
|
|
|
self.user_name.setObjectName('user_name')
|
|
|
|
self.user_mail = QLabel('794508986@qq.com')
|
|
|
|
self.user_mail.setObjectName('user_mail')
|
2022-04-01 22:25:19 +08:00
|
|
|
self.user_mail.setStyleSheet('font-size:16px')
|
2022-04-04 22:34:07 +08:00
|
|
|
self.menu_label = QLabel('')
|
|
|
|
self.menu_label.setObjectName('menu')
|
|
|
|
self.menu_label.setPixmap(
|
|
|
|
QPixmap(os.path.abspath('../') + '/images/up-down.svg').scaled(20, 20, Qt.IgnoreAspectRatio,
|
|
|
|
Qt.SmoothTransformation))
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
|
|
info_layout.addWidget(self.user_name)
|
|
|
|
info_layout.addWidget(self.user_mail)
|
2022-04-04 22:34:07 +08:00
|
|
|
layout.addLayout(info_layout, 4)
|
|
|
|
layout.addStretch(1)
|
|
|
|
layout.addWidget(self.menu_label, 1)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
|
|
self.widget.setLayout(layout)
|
2022-04-04 22:34:07 +08:00
|
|
|
# 设置右键菜单
|
|
|
|
self.context_menu = QMenu(self)
|
|
|
|
self.init_menu()
|
|
|
|
|
|
|
|
# def mouseReleaseEvent(self, QMouseEvent):
|
|
|
|
# self.button_clicked_signal.emit()
|
|
|
|
#
|
|
|
|
|
|
|
|
# 可在外部与槽函数连接 用处不大
|
|
|
|
# def connect_customized_slot(self, func):
|
|
|
|
# self.button_clicked_signal.connect(func)
|
|
|
|
|
|
|
|
def contextMenuEvent(self, event):
|
|
|
|
self.context_menu.exec_(event.globalPos())
|
|
|
|
|
|
|
|
def init_menu(self):
|
|
|
|
# 背景透明
|
|
|
|
self.context_menu.setAttribute(Qt.WA_TranslucentBackground)
|
|
|
|
# 无边框、去掉自带阴影
|
|
|
|
self.context_menu.setWindowFlags(
|
|
|
|
self.context_menu.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint)
|
|
|
|
|
|
|
|
self.context_menu.addAction(QIcon(os.getcwd() + '/../images/setting.svg'), '设置', self.setting)
|
|
|
|
|
|
|
|
self.context_menu.addAction(QIcon(os.getcwd() + '/../images/sync.svg'), '同步', self.sync)
|
|
|
|
self.context_menu.addAction(QIcon(os.getcwd() + '/../images/sync.svg'), '退出', self.exit_account)
|
|
|
|
|
|
|
|
# todo
|
|
|
|
# 设置右键点击事件
|
|
|
|
def setting(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def sync(self):
|
|
|
|
pass
|
2022-04-01 22:25:19 +08:00
|
|
|
|
2022-04-04 22:34:07 +08:00
|
|
|
def exit_account(self):
|
|
|
|
pass
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
|
|
|
2022-04-04 22:34:07 +08:00
|
|
|
# if __name__ == "__main__":
|
|
|
|
# app = QApplication(sys.argv)
|
|
|
|
# main = User()
|
|
|
|
# style_sheet = QSSLoader.read_qss_file('../resource/current.qss')
|
|
|
|
# main.setStyleSheet(style_sheet)
|
|
|
|
# # print(os.path.abspath('../'))
|
|
|
|
#
|
|
|
|
# app.setWindowIcon(QIcon(os.path.abspath('../') + '/images/todo.svg'))
|
|
|
|
# main.show()
|
|
|
|
# sys.exit(app.exec_())
|