Conversation
|
I know it is not complete. The one you point is on FitPeakSelect. The approach I followed to be able to keep using the yellow background is to set the foreground as black when using the yellow background. I think the three files I modified should illustrate most cases. The most dificult was QPeriodicTable. The label on the top left should also be of the default color for text and not forced to be black. |
|
It was intense... LLM helped a lot, but still a lot of manual search and testing. few problems and notes:
Probably the |
Be careful. You have introduced very dangerous code by using self.palette() combined with self.setPalette() self.palette() gives you back a const If you wand to modify it and use the modified palette, you have to make a copy. That was the reason of using qt.QPalette() That constructor is available on all versions of Qt. If the constructor qt.QPalette(const QPalette &p) is available it is an alternative. |
I though most of Qt wrappers are "safe" by design and they return a copy if modified... I mean that if I call >>> import sys
>>> from PySide6.QtWidgets import QApplication, QWidget
>>> from PySide6.QtGui import QColor
>>> app = QApplication(sys.argv)
>>> w = QWidget()
>>> original_palette = w.palette()
>>> pal = w.palette()
>>> pal == original_palette
True
>>> w.palette().color(w.palette().ColorRole.Window)
PySide6.QtGui.QColor.fromRgbF(0.117647, 0.117647, 0.117647, 1.000000)
>>> pal.setColor(pal.ColorRole.Window, QColor("red"))
>>> pal == original_palette
False
>>> w.palette().color(w.palette().ColorRole.Window)
PySide6.QtGui.QColor.fromRgbF(0.117647, 0.117647, 0.117647, 1.000000)
>>> w.setPalette(pal)
>>> w.palette().color(w.palette().ColorRole.Window)
PySide6.QtGui.QColor.fromRgbF(1.000000, 0.000000, 0.000000, 1.000000)but maybe i am missing smthg else... |
Yes, that would be safe. Python does not have the notion of const &. I can assure that assuming wrappers were returning a copy led to crashes in the past. In C++ you cannot modify a const and you have to make a copy if you want to modify it. Therefore you have to use a new QPalette. Either using the QPalette() constructor as I did (thus tested) or the QPalette(const QPalette &) constructor. |
Most of the HTML code was used to generate actual web pages that expected to have a white background. Making sure the background is white and the text black should be the safest approach at this point. Those pages were expected to be read in a browser, not inside PyMca. They are quite often printed with a screen copy. A black is certainly not the best in those cases.
At this point it just needs to be readable. Force white background and black foreground. To me is the same situation as for the plots that assume a white background. Again, screen copy to add into documents is envisageable.
Fine.
For QLineEdit I agree. For the QPeriodicTable I disagree.
Wrong. Make sure you make a copy or use a new palette. It was not by chance that I made sure I was not modifying an underlying constant C++ palette.
Probably you are right. In any case a black text on a yellow background will always be visible. When that is not forced, we obtain sometimes black on grey that is barely visible.
To me is enough to get the code usable in dark mode. Not to waste time on making everything dark friendly (particularly web pages or things expected to be printed) |
There was forced white background - which I do not understand.
Why to force more colors instead not forcing them at all and then it looks better? (main change was to remove forced white background see changes in
OK will switch back to yellow type colors for selection in
I will switch to By the way direct implementation of
it seems that in current state it is quite nice on Windows. Just to mention - MacOS |
In FitPeakSelect I would follow the same approach as in QPeriodicTable (use a styleSheet) |
If in the browser looks OK that removes at lot of my objections. |
|
As discussed in #1184
It is doable for the frozen binaries since there we use 6.5+. But I would probably avoid it for now since PyMca support PyQt5 and PyQt6 < 6.5, which do not have this feature. |
One could always check the Qt version, but I am fine with whatever choice you make. |
…PeakSelect to have a common yellow-grey scheme
|
I cleaned all
As for I will run |
|
Please check explicitly changes in HTMLs appeared in windows (FitPeakSelect, ElementsInfo, PeakIdentifier, Diagnostics in fit) are not forced to 'white'. Report HTML is now forced to be white as before + additionally text forced to be black. Thus, it should have the style as before. I checked by fitting random xrf data seems same for Dark/Light mode. Will it work like this for you? |
|
I am still trying on a fake dark (adding app.styleHints().setColorScheme(qt.Qt.ColorScheme.Dark) to PyMcaMain) but it looks quite nice and usable. Nice work! |
|
I have just added one comment above about a probably unnecessary paintEvent code for the EnergyTable. Besides that, I think it can be merged. A release candidate could be provided for testing purposes. |
|
There was already a patcher in I left |
|
For me is good enough to merge it but you are the reviewer :-) |
|
I would run the I am going to do:
If i miss smthg let me know. Update: dry-run |
When a new palette is used, things are safe. You should not worry about. paintEvent is called very often by Qt. If one can avoid to overwrite it in python, it is better but if you cannot achieve the desired behavior do as you want. |
Take a look at all the tables and so on. It is just the press-button exercise described in http://www.silx.org/doc/PyMca/dev/training/tertiary/index.html |
|
I will implement After testing I would say that there are 3 issues:
|
|
After several attempts to fix EnergyTable using forced magenta color I miserably failed to make it look good and stable on Windows for Pyside6==6.10.2. Problem is that the current situation via only A hack to noticeJust to notice.There is a mixed (a bit ugly) solution which make it same (as current state) on all Qt versions (fixing #1179 for EnergyTable): def setColor(self, color):
self.color = color
if color == self._backgroundColor:
self.setStyleSheet("color: %s; background-color: %s;" % \
(self._textColor.name(), self._backgroundColor.name()))
else:
self.setStyleSheet("color: %s; background-color: %s;" % \
(self._selectedTextColor.name(), self._selectedBackgroundColor.name()))
# reset checkbox indicator to follow OS for Qt>=6.9 (needed for Windows)
# on Qt<=6.8 it make no changes
palette = qt.QPalette(qt.QApplication.instance().palette())
palette.setColor(
qt.QPalette.ColorGroup.Active,
self.foregroundRole(),
self._selectedTextColor
)
self.setPalette(palette) |
|
ElementsInfo - fixed |
from c4b8782 - "be ready for dark mode" on Qt 6.10.2: Just to clarify my "problem" is this (was -vs- now) :
|












































@sergey-yaroslavtsev
This pull request as it is handles most of the examples shown in #1178
Please feel free to complete it (or not)