更改QMessageBox PyQt5中的字体颜色

时间:2014-07-04 22:08:20

标签: python-3.x pyqt5

我正在尝试将所有字体颜色更改为MessageBox内容中的白色,但它也不会将href字体颜色更改为白色。 这是代码:

def MsgBox(self):
        qmsgBox = QMessageBox()
        qmsgBox.setStyleSheet('QMessageBox {background-color: #2b5b84; color: white;}\n QMessageBox {color: white;}\n QPushButton{color: white; font-size: 16px; background-color: #1d1d1d; border-radius: 10px; padding: 10px; text-align: center;}\n QPushButton:hover{color: #2b5b84;}')
        QMessageBox.about(qmsgBox, 'SuperPyQtCalculator',
            """<font color='white'><p><b>SuperPyQtCalculator</b></p>
            <p><b>Version:</b> {0}</p>
            <p><b>Author: </b> {1}</p>
            <p><b>Web:</b> <a href='www.linuxmusica.com'>Linux Music 3.0</a></p>
            <p><b>Copyright:</b>  &copy; 2014 Qtrac Ltd.
            All rights reserved.
            <p>This application can be used to calculate
            simple math science operations.</p>
            <p><b>You are using:</b></p>
            <p>Python {2} - Qt {3} - PyQt {4} on {5}</p></font>""".format(
            __version__, __author__, platform.python_version(),
            QT_VERSION_STR, PYQT_VERSION_STR, platform.system()))

我无法使用样式表和html属性更改a href颜色。 感谢

1 个答案:

答案 0 :(得分:4)

好的,我已经找到了一个解决方案,它不是最优的解决方案,但对我来说很有用。它包括将“字体颜色”直接应用于href文本,而不是a href。这是代码:

def MsgBox(self):
        qmsgBox = QMessageBox()
        qmsgBox.setStyleSheet('QMessageBox {background-color: #2b5b84; color: white;}\nQPushButton{color: white; font-size: 16px; background-color: #1d1d1d; border-radius: 10px; padding: 10px; text-align: center;}\n QPushButton:hover{color: #2b5b84;}')
        QMessageBox.about(qmsgBox, 'SuperPyQtCalculator',
            """<font color='white'><p><b>SuperPyQtCalculator</b></p>
            <p><b>Version:</b> {0}</p>
            <p><b>Author: </b> {1}</p>
            <p><b>Web:</b></font><a href='www.linuxmusica.com'><font color='black'>Linux Music 3.0</font></a></p>
            <font color='white'><p><b>Email: </b>lopeztobal@gmail.com</p>
            <p><b>Copyright:</b>  &copy; 2014 Qtrac Ltd.
            All rights reserved.
            <p>This application can be used to calculate
            simple math science operations.</p>
            <p><b>You are using:</b></p>
            <p>Python {2} - Qt {3} - PyQt {4} on {5}</p></font>""".format(
            __version__, __author__, platform.python_version(),
            QT_VERSION_STR, PYQT_VERSION_STR, platform.system()))
相关问题