I'm having an issue with your patch: QStyle::name has only been added in Qt
6.1 (https://doc.qt.io/qt-6/qstyle.html#name). I believe
QObject::objectName should do the trick too.

As I understand your problem, in LyX.cpp, LyX::exec first creates a
GuiApplication (line 358) before initialising LyX (line 366). If I do the
initialisation in GuiApplication::exec instead, I don't get any crash;
actually, your patch works :)!
I have added a similar line in PrefInput::applyRC so that the style change
applies immediately when clicking Apply in the Preferences window.
I'm attaching the corresponding patch.

Side question: why is createApplication declared in Application.h but
defined in GuiApplication.cpp?

Thibaut Cuvelier


On Fri, 7 Jul 2023 at 02:23, Thibaut Cuvelier <dourou...@gmail.com> wrote:

> On Thu, 6 Jul 2023 at 10:34, Yu Jin <technikma...@gmail.com> wrote:
>
>> Am Do., 6. Juli 2023 um 03:47 Uhr schrieb Thibaut Cuvelier:
>>
>>> On Wed, 5 Jul 2023 at 22:02, Enrico Forestieri wrote:
>>>
>>>> On Wed, Jul 05, 2023 at 08:42:21PM +0200, Pavel Sanda wrote:
>>>> >
>>>> >I think your patch should go for windows port only as it would
>>>> probably
>>>> >interfere with ppl choosing windows style under linux (yes, apparently
>>>> >there are users choosing this as I read users list).
>>>>
>>>> I don't think this is a good idea because LyX would look different from
>>>> any other application.
>>>>
>>>
>>> +1, the Fusion style isn't native at all (the colours are completely
>>> off, for instance). Maybe some users will like it, though (like the author
>>> of https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5).
>>>
>>> However, it seems that the classic Windows theme has a dark mode
>>> starting with Qt 6.5 (out since April):
>>> https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5. The Windows
>>> style, both in Qt 5 and Qt 6, is horrible, though... Here is what it looks
>>> like (2.4 beta 3 with Qt 6.5.1 as built by Eugene; run with:
>>> .\LyX.exe -platform windows:darkmode=2 -style windows
>>> ):
>>>
>>> What's strange is that the situation isn't much better for Qt Quick,
>>> with no native Windows dark theme. There are other open-source projects
>>> that provide a good Windows theme that also works in dark, such as
>>> https://github.com/witalihirsch/QTWin11 for Python only or
>>> https://github.com/marunemitsu/QTFluent (very modern style, unlike the
>>> default Vista one). I have seen good results with
>>> https://github.com/ColinDuquesnoy/QDarkStyleSheet (but not with its
>>> light theme!), which is more or less maintained and should work with Qt 6
>>> (not PyQt 6 out of the box, though). Wireshark went that route, but the
>>> code didn't get merged (
>>> https://gitlab.com/wireshark/wireshark/-/merge_requests/6382).
>>>
>>> Overall, it seems that Qt's dark theme for Windows is inexistent; their
>>> preferred solution is to avoid implementing a proper theme, so that people
>>> have to rely on unmaintained projects or use their own solution. They rely
>>> consider it done (
>>> https://bugreports.qt.io/browse/QTBUG-72028#comment-712180)!
>>>
>>> How complex would it be to have a new LyX setting to choose the Qt
>>> theme? I believe it should not be too hard, as you can change the style on
>>> QApplication. Or is there something I'm missing?
>>>
>>
>> I tried my luck here (patch attached) but it is not working though. While
>> I think I got the UI and LyXRC right, the problem is that at the time of
>> creation of QApplication the LyXRC is initialized but not read, so the
>> saved style preference is not available.
>>
>> This stacktrace is from application creation:
>>   LyX.exe!lyx::createApplication(int & argc, char * * argv) Zeile 224 C++
>>   LyX.exe!lyx::LyX::exec(int & argc, char * * argv) Zeile 358 C++
>>   LyX.exe!main(int argc, char * * argv) Zeile 55 C++
>>
>> This one from LyXRC reading:
>>   LyX.exe!lyx::LyXRC::read(lyx::Lexer & lexrc, bool check_format) Zeile
>> 608 C++
>>   LyX.exe!lyx::LyXRC::read(const lyx::support::FileName & filename, bool
>> check_format) Zeile 242 C++
>>   LyX.exe!lyx::LyX::readRcFile(const std::string & name, bool
>> check_format) Zeile 1148 C++
>>   LyX.exe!lyx::LyX::init() Zeile 998 C++
>>   LyX.exe!lyx::LyX::init(int & argc, char * * argv) Zeile 483 C++
>>   LyX.exe!lyx::LyX::exec(int & argc, char * * argv) Zeile 366 C++
>>   LyX.exe!main(int argc, char * * argv) Zeile 55 C++
>>
>> second function from bottom: line 358 vs 366.
>>
>> Any ideas what I could do here?
>>
>
> Can't you use setStyle later on, once LyXRC is read? I suspect it should
> be enough to apply the style to the whole application, based on the source
> code (
> https://github.com/qt/qtbase/blob/dev/src/widgets/kernel/qapplication.cpp#L971),
> as I understand that GuiApplication is the root widget for the whole LyX.
>
> Also, I believe that LyXRC shouldn't take precedence over CLI arguments
> (-style windows, for instance); does Qt implement this itself or do we have
> to check in QCoreApplication::arguments if a style is given?
>

Attachment: Implement_style_selection_dialog.patch
Description: Binary data

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to