Added QWhatsThis to known issues.

Created sample workaround in `example/whatsthis.py`, showing how to
style the `QWhatsThis` widget using `QPalette`, and added a workaround
description to `ISSUES.md`.

Closes #59.
main
Alex Huszagh 2022-05-03 16:59:41 -05:00
parent 8f17872d47
commit d006be8949
3 changed files with 151 additions and 0 deletions

View File

@ -18,6 +18,8 @@ There are limitations to what can be styled with stylesheets, as well as rare bu
- [Links](#links) - [Links](#links)
- [QToolButton](#qtoolbutton) - [QToolButton](#qtoolbutton)
- [Menu Button Padding](#menu-button-padding) - [Menu Button Padding](#menu-button-padding)
- [QWhatsThis]
- [Tooltip Colors](#tooltip-colors)
- [QWidget] - [QWidget]
- [Standard Icons](#standard-icons) - [Standard Icons](#standard-icons)
@ -220,6 +222,61 @@ def main():
The default icon for `QCommandLinkButton` is platform-dependent, and depends on the standard icon `SP_CommandLink` (which cannot be specified in a stylesheet). See [Standard Icons](#standard-icons) for an explanation on how to override this standard icon. The default icon for `QCommandLinkButton` is platform-dependent, and depends on the standard icon `SP_CommandLink` (which cannot be specified in a stylesheet). See [Standard Icons](#standard-icons) for an explanation on how to override this standard icon.
# QWhatsThis
### Tooltip Colors
QWhatsThis uses `QPalette::toolTipText` and `QPalette::toolTipBase` for its colors: unfortunately, these are not influenced by the stylesheet. To modify these, you can change the colors for `QPalette::ToolTipBase` and `QPalette::ToolTipText`. An example can be found in [whatsthis.py](/example/whatsthis.py).
A simple example of modifying the tooltip palette for the `QWhatsThis` style is as follows:
**C++**
```cpp
#include <QApplication>
#include <QColor>
#include <QPalette>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
auto palette = app.palette();
QColor green(0, 255, 0);
QColor blue(0, 0, 255);
palette.setColor(QPalette::ToolTipBase, green);
palette.setColor(QPalette::ToolTipText, blue);
app.setPalette(palette);
...
return app.exec();
}
```
**Python**
```python
import sys
from PyQt6 import QtGui, QtWidgets
ColorRole = QtGui.QPalette.ColorRole
def main():
app = QtWidgets.QApplication(sys.argv)
palette = app.palette()
green = QtGui.QColor(0, 255, 0)
blue = QtGui.QColor(0, 0, 255)
palette.setColor(ColorRole.ToolTipBase, green)
palette.setColor(ColorRole.ToolTipText, blue)
app.setPalette(palette)
...
return app.exec()
```
# QWidget # QWidget
### Standard Icons ### Standard Icons

View File

@ -233,6 +233,8 @@ def get_compat_definitions(args):
ns.HoverMove = ns.EventType.HoverMove ns.HoverMove = ns.EventType.HoverMove
ns.HoverLeave = ns.EventType.HoverLeave ns.HoverLeave = ns.EventType.HoverLeave
ns.PlaceholderText = ns.ColorRole.PlaceholderText ns.PlaceholderText = ns.ColorRole.PlaceholderText
ns.ToolTipBase = ns.ColorRole.ToolTipBase
ns.ToolTipText = ns.ColorRole.ToolTipText
ns.NoTicks = ns.TickPosition.NoTicks ns.NoTicks = ns.TickPosition.NoTicks
ns.TicksAbove = ns.TickPosition.TicksAbove ns.TicksAbove = ns.TickPosition.TicksAbove
ns.TicksBelow = ns.TickPosition.TicksBelow ns.TicksBelow = ns.TickPosition.TicksBelow
@ -473,6 +475,8 @@ def get_compat_definitions(args):
ns.HoverMove = QtCore.QEvent.HoverMove ns.HoverMove = QtCore.QEvent.HoverMove
ns.HoverLeave = QtCore.QEvent.HoverLeave ns.HoverLeave = QtCore.QEvent.HoverLeave
ns.PlaceholderText = QtGui.QPalette.PlaceholderText ns.PlaceholderText = QtGui.QPalette.PlaceholderText
ns.ToolTipBase = QtGui.QPalette.ToolTipBase
ns.ToolTipText = QtGui.QPalette.ToolTipText
ns.NoTicks = QtWidgets.QSlider.NoTicks ns.NoTicks = QtWidgets.QSlider.NoTicks
ns.TicksAbove = QtWidgets.QSlider.TicksAbove ns.TicksAbove = QtWidgets.QSlider.TicksAbove
ns.TicksBelow = QtWidgets.QSlider.TicksBelow ns.TicksBelow = QtWidgets.QSlider.TicksBelow
@ -642,6 +646,8 @@ def get_colors(args, compat):
ns.Selected = compat.QtGui.QColor(61, 174, 233) ns.Selected = compat.QtGui.QColor(61, 174, 233)
ns.PlaceholderColor = compat.QtGui.QColor(255, 0, 0) ns.PlaceholderColor = compat.QtGui.QColor(255, 0, 0)
ns.TickColor = compat.QtGui.QColor(255, 0, 0) ns.TickColor = compat.QtGui.QColor(255, 0, 0)
ns.ToolTipBase = compat.QtGui.QColor(0, 255, 0)
ns.ToolTipText = compat.QtGui.QColor(0, 0, 255)
if 'dark' in args.stylesheet: if 'dark' in args.stylesheet:
ns.GrooveBackground = compat.QtGui.QColor(98, 101, 104) ns.GrooveBackground = compat.QtGui.QColor(98, 101, 104)
ns.GrooveBorder = compat.QtGui.QColor(49, 54, 59) ns.GrooveBorder = compat.QtGui.QColor(49, 54, 59)
@ -650,6 +656,8 @@ def get_colors(args, compat):
ns.Notch = compat.QtGui.QColor(51, 78, 94) ns.Notch = compat.QtGui.QColor(51, 78, 94)
ns.PlaceholderColor = compat.QtGui.QColor(118, 121, 124) ns.PlaceholderColor = compat.QtGui.QColor(118, 121, 124)
ns.TickColor = compat.QtGui.QColor(51, 78, 94) ns.TickColor = compat.QtGui.QColor(51, 78, 94)
ns.ToolTipBase = compat.QtGui.QColor(49, 54, 59)
ns.ToolTipText = compat.QtGui.QColor(239, 240, 241)
elif 'light' in args.stylesheet: elif 'light' in args.stylesheet:
ns.GrooveBackground = compat.QtGui.QColor(106, 105, 105, 179) ns.GrooveBackground = compat.QtGui.QColor(106, 105, 105, 179)
ns.GrooveBorder = compat.QtGui.QColor(239, 240, 241) ns.GrooveBorder = compat.QtGui.QColor(239, 240, 241)
@ -658,6 +666,8 @@ def get_colors(args, compat):
ns.Notch = compat.QtGui.QColor(61, 173, 232, 51) ns.Notch = compat.QtGui.QColor(61, 173, 232, 51)
ns.PlaceholderColor = compat.QtGui.QColor(186, 185, 184) ns.PlaceholderColor = compat.QtGui.QColor(186, 185, 184)
ns.TickColor = compat.QtGui.QColor(61, 173, 232, 51) ns.TickColor = compat.QtGui.QColor(61, 173, 232, 51)
ns.ToolTipBase = compat.QtGui.QColor(49, 54, 59)
ns.ToolTipText = compat.QtGui.QColor(239, 240, 241)
return ns return ns

84
example/whatsthis.py Normal file
View File

@ -0,0 +1,84 @@
#!/usr/bin/env python
#
# The MIT License (MIT)
#
# Copyright (c) <2022-Present> <Alex Huszagh>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
'''
whatsthis
=========
Example showing how to style the tooltip base and text for QWhatsThis,
since it cannot be modified via stylesheets.
'''
import shared
import sys
parser = shared.create_parser()
args, unknown = shared.parse_args(parser)
QtCore, QtGui, QtWidgets = shared.import_qt(args)
compat = shared.get_compat_definitions(args)
colors = shared.get_colors(args, compat)
class Ui:
'''Main class for the user interface.'''
def setup(self, MainWindow):
MainWindow.setObjectName('MainWindow')
MainWindow.resize(1068, 824)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName('centralwidget')
self.layout = QtWidgets.QVBoxLayout(self.centralwidget)
self.layout.setObjectName('layout')
self.layout.setAlignment(compat.AlignHCenter)
MainWindow.setCentralWidget(self.centralwidget)
self.toolbar = QtWidgets.QToolBar('Toolbar')
self.toolbar.setOrientation(compat.Vertical)
self.action = compat.QAction('&Action 1', MainWindow)
self.action.setWhatsThis('Example action')
self.toolbar.addAction(self.action)
self.toolbar.addAction(QtWidgets.QWhatsThis.createAction(self.toolbar))
MainWindow.addToolBar(compat.TopToolBarArea, self.toolbar)
def main():
'Application entry point'
app, window = shared.setup_app(args, unknown, compat)
palette = app.palette()
palette.setColor(compat.ToolTipBase, colors.ToolTipBase)
palette.setColor(compat.ToolTipText, colors.ToolTipText)
app.setPalette(palette)
# setup ui
ui = Ui()
ui.setup(window)
window.setWindowTitle('Stylized QWhatsThis.')
shared.set_stylesheet(args, app, compat)
return shared.exec_app(args, app, window, compat)
if __name__ == '__main__':
sys.exit(main())