2014-07-04 252 views
2

我试图在MessageBox内容中将所有字体颜色更改为白色,但它不会将href字体颜色也更改为白色。 下面的代码:更改QMessageBox中的字体颜色PyQt5

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())) 

我不能与A HREF颜色样式并与HTML属性附加伤害发生变化。 谢谢

回答

3

好吧,我已经找到了一个解决方案,它不是最佳的解决方案,但它对我有用。它包括将“字体颜色”直接添加到一个href文本,而不是一个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>[email protected]</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()))