2014-07-04 283 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()))