Document workarounds for link colors.
You cannot modify the default link color in a stylesheet, so document the 2 ways to modify the link color via either the `style` atttibute of the `a` tag, or using the `QPalette:Link` color role. Closes #58.main
parent
78b65c217d
commit
0ce688bf40
60
ISSUES.md
60
ISSUES.md
|
@ -15,6 +15,7 @@ There are limitations to what can be styled with stylesheets, as well as rare bu
|
|||
- [Triangular Tab Padding](#triangular-tab-padding)
|
||||
- [QTextDocument](#qtextdocument)
|
||||
- [Placeholder Text](#placeholder-text)
|
||||
- [Links](#links)
|
||||
- [QToolButton](#qtoolbutton)
|
||||
- [Menu Button Padding](#menu-button-padding)
|
||||
- [QWidget]
|
||||
|
@ -105,6 +106,65 @@ def main():
|
|||
return app.exec()
|
||||
```
|
||||
|
||||
### Links
|
||||
|
||||
There is no way to set the default color of a link in a `QLabel`, `QTextEdit`, `QPlainTextEdit`, `QTextBrowser`, `QMessageBox`, etc. There are a few possible workarounds.
|
||||
|
||||
One is to set the link color when setting the label text, here, setting the label text to red. This will override the default color, and you can use a theme-dependent color to ensure the links are rendered properly.
|
||||
|
||||
```python
|
||||
label = QtWidgets.QLabel()
|
||||
# Ensure it's displayed as a URL
|
||||
label.setTextFormat(QtCore.Qt.TextFormat.RichText)
|
||||
label.setText('<a href="https://google.com" style="color: red;">Google</a>')
|
||||
```
|
||||
|
||||
However, this won't work with markdown input, and requires you to modify any existing text to include the styles, which is undesirable. A better solution is to set a default palette for `ColorRole.Link`.
|
||||
|
||||
**C++**
|
||||
|
||||
```cpp
|
||||
#include <QApplication>
|
||||
#include <QColor>
|
||||
#include <QPalette>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
auto palette = app.palette();
|
||||
QColor red(255, 0, 0);
|
||||
palette.setColor(QPalette::Active, QPalette::Link, red);
|
||||
app.setPalette(palette);
|
||||
|
||||
...
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
```
|
||||
|
||||
**Python**
|
||||
|
||||
```python
|
||||
import sys
|
||||
from PyQt6 import QtGui, QtWidgets
|
||||
|
||||
ColorGroup = QtGui.QPalette.ColorGroup
|
||||
ColorRole = QtGui.QPalette.ColorRole
|
||||
|
||||
def main():
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
|
||||
palette = app.palette()
|
||||
red = QtGui.QColor(255, 0, 0)
|
||||
palette.setColor(ColorGroup.Active, ColorRole.Link, red)
|
||||
app.setPalette(palette)
|
||||
|
||||
...
|
||||
|
||||
return app.exec()
|
||||
```
|
||||
|
||||
# QToolButton
|
||||
|
||||
### Menu Button Padding
|
||||
|
|
Loading…
Reference in New Issue