countLabel
悬停时如何使工具提示具有正常的矩形形状,而不是圆形?
import PyQt5
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget, QMainWindow, QAction, qApp
from PyQt5.QtGui import QIcon
HEIGHT = 750
WIDTH = 1300
class Menu(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.menubar = parent.menuBar()
self.file = self.menubar.addMenu('&Опции')
self.exitAction = QAction(QIcon('icons/cross-exit.ico'), '&Exit', self)
self.exitAction.setShortcut('Ctrl+Q')
self.exitAction.setStatusTip('Exit application')
self.exitAction.triggered.connect(parent.close)
self.file.addAction(self.exitAction)
def addMenu(self, actionName, text, command, icon, shortcut=None, statusTip=None) :
self.actionName = QAction(QIcon(icon), text, self)
if shortcut:
self.actionName.setShortcut(shortcut)
if statusTip:
self.actionName.setStatusTip(statusTip)
self.actionName.triggered.connect(command)
self.file.insertAction(self.exitAction, self.actionName)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.q = QDesktopWidget().availableGeometry()
self.r_w, self.r_h = self.q.width(), self.q.height()
self.setGeometry(self.r_w/2-WIDTH/2, self.r_h/2-HEIGHT/2, WIDTH, HEIGHT)
self.w = self.size().width()
self.h = self.size().height()
print(self.w, self.h)
self.setFixedSize(1300, 750)
self.setWindowTitle('Lings')
self.setWindowIcon(QIcon('icons/Lings.ico'))
self.label = QtWidgets.QLabel("sdsd", self)
self.labelAnswer = QtWidgets.QLabel(self)
self.labelEdit = QtWidgets.QLineEdit(self)
self.countLabel = QtWidgets.QLabel('0', self)
self.l_w, self.l_h = 500, 100
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.countLabel.setAlignment(QtCore.Qt.AlignCenter)
self.labelEdit.setAlignment(QtCore.Qt.AlignCenter)
self.labelAnswer.resize(self.l_w, self.l_h)
self.countLabel.resize(50, 50)
self.labelEdit.resize(self.l_w, self.l_h)
self.labelAnswer.move(self.w/2-self.l_w/2, 250)
self.countLabel.move(self.w/2-self.l_w/2+550, 275)
self.labelEdit.move(self.w/2-self.l_w/2, 400)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.resize(self.l_w, self.l_h)
self.label.move(self.w/2-self.l_w/2, 100)
self.label.setFont(QtGui.QFont('Verdana', 24))
self.labelAnswer.setFont(QtGui.QFont('Verdana', 24))
self.labelEdit.setFont(QtGui.QFont('Verdana', 24))
self.label.setStyleSheet("background-color: #E0FFFF;")
self.labelAnswer.setStyleSheet("background-color: #E0FFFF")
self.labelEdit.setStyleSheet("background-color: #7FFFD4; border: none")
self.countLabel.setToolTip("Ваша серия правильных ответов") #?????????????????????
self.countLabel.setStyleSheet("""
font-size: 15px;
border-radius: 25px;
min-height: 50px;
max-height: 50px;
min-width: 50px;
max-width: 50px;
background-color: #FAF0E6;
border: 1px double #ADD8E6;
""")
self.menu = Menu(self)
self.menu.addMenu('action', 'New', lambda: SecondWindow(self), 'icons/test.ico', shortcut="Ctrl+D", statusTip="Creating")
self.menu.addMenu('Eng', 'С английского на русский', lambda: SecondWindow(self), 'icons/eng-rus.ico', shortcut="Ctrl+D", statusTip="Creating")
self.menu.addMenu('Rus', 'С русского на английский', lambda: SecondWindow(self), 'icons/rus-eng.ico', shortcut="Ctrl+D", statusTip="Creating")
self.show()
class SecondWindow(QWidget):
def __init__(self, parent=None):
super().__init__(parent, QtCore.Qt.Window)
self.initUI()
def initUI(self):
self.q = QDesktopWidget().availableGeometry()
self.r_w, self.r_h = self.q.width(), self.q.height()
self.setGeometry(self.r_w/2-WIDTH/2, self.r_h/2-HEIGHT/2, WIDTH, HEIGHT)
self.setFixedSize(1300, 800)
self.setWindowTitle('Lings2')
self.setWindowIcon(QIcon('icons/Lings.ico'))
self.mainLayout = QtWidgets.QVBoxLayout()
self.buttons = []
for i in range(5):
but = QtWidgets.QPushButton('button {}'.format(i), self)
self.mainLayout.addWidget(but)
self.buttons.append(but)
self.setLayout(self.mainLayout)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
styleFile="styles/styles.qss"
with open(styleFile,"r") as sf:
app.setStyleSheet(sf.read())
mainWindow = MainWindow()
sys.exit(app.exec_())```
为
QToolTip