xiaoyifang / goldendict-ng

The Next Generation GoldenDict
https://xiaoyifang.github.io/goldendict-ng/
Other
1.56k stars 82 forks source link

深色模式下查词时,闪现白色背景色 (White flash in dark reader mode) #357

Closed opiater closed 9 months ago

opiater commented 1 year ago

版本信息: Goldendict 23.02.07-alpha.230225.da004ee9 macos darwin 19.6.0 Qt 6.4.2 x86_64-little_endian-lp64 Clang 13.0.0 (clang-1300.0.29.30) Flags: MAKE_ZIM_SUPPORT MAKE_CHINESE_CONVERSION_SUPPORT

也就是说,未完全加载完前,会显示软件界面更下层的白色底色。 新增加的内置深色模式总体效果很好,不过这个闪现白底色的问题比较影响观感。

xiaoyifang commented 1 year ago

@shenlebantongying can you check on this? Is this related with the following code https://github.com/xiaoyifang/goldendict/blob/eb1206945bab3b91fe8cf811a5c42fe82383ab63/article_maker.cc#L164-L166

opiater commented 1 year ago

闪现白色背景的问题在更新版本中依然存在。

Goldendict 23.02.07-alpha.230309.37e3df05 macos darwin 19.6.0 Qt 6.4.2 x86_64-little_endian-lp64 Clang 13.0.0 (clang-1300.0.29.30) Flags: MAKE_ZIM_SUPPORT MAKE_CHINESE_CONVERSION_SUPPORT

xiaoyifang commented 1 year ago

会不会是词典本身里面设置了白色背景

opiater commented 1 year ago

会不会是词典本身里面设置了白色背景

没有,也检查了配置文件夹里的qt-style.css和所用“附加样式”的article-style.css,没有或删除背景设置后,依然闪现白色背景。 你和其他用户没有这个问题吗?

shenlebantongying commented 1 year ago

It looks like we should also set background via https://doc.qt.io/qt-6/qwebenginepage.html#backgroundColor-prop

xiaoyifang commented 1 year ago

It looks like we should also set background via https://doc.qt.io/qt-6/qwebenginepage.html#backgroundColor-prop

I have tried this method, has not solved the white flash.

https://github.com/xiaoyifang/goldendict/tree/fix/darkmode-white-flash

xiaoyifang commented 1 year ago

I began to suspect that the white background flash is not caused by dark reader mode. This issue is only more significant in dark reader mode

xiaoyifang commented 1 year ago

https://github.com/qutebrowser/qutebrowser/issues/2912 https://stackoverflow.com/questions/43150506/opacity-not-working-with-qwebengineview-and-translucent-background

shenlebantongying commented 1 year ago

I think the changes in the PR above is unrelated. Articleview.cc is a QFrame while the doc that I linked is a QWebEnginePage. This is yet another confusing "same method name but used for different class".

The setBackground should be used withArticleWebPage.

Sadly, I tried and it does not work. Only the initial background is changed, and the white flash still exist when searching new words. It only removes the white flash when opening a new tab.

shenlebantongying commented 1 year ago

I think I figured out the actual problem, but I don't have a fix.

It is unrelated to Qt.

The white flash comes from Chromium when opening a new page. In chrome, you will get a similar white flash when navigating to a page on a different domain (We don't even change domain?? Maybe we can trick chromium to think we are on the same domain???).

When a search is initiated by a user, the code will end up at ArticleView::showDefinition

https://github.com/xiaoyifang/goldendict/blob/fa06c85d6d617e07e7e7a40d529db2392f5c0bd5/articleview.cc#L405-L406

This req's url will be gdlookup://something and will be loaded like opening a new webpage in chrome.

Here the "white flash" happens! It is the embedded chromium that shows white when open a new page.

Google those things will show some generic solutions:

Also see https://github.com/darkreader/darkreader/issues/3811

A fix if we cannot figure out something else: hide the ArticleView before loading a new page and show it up after the page is loaded)

Another fix: instead of reusing the same QWebEnginePage and QWebEnginePage::load, we can create a new page with setbackground(black) for every search, and swap out the existing one with QWebEngineView::setPage? This will destroy a page's history.

xiaoyifang commented 1 year ago

image

this extension can be installed in the chrome to enable the dark reader mode

xiaoyifang commented 1 year ago

I think the changes in the PR above is unrelated. Articleview.cc is a QFrame

I think you have pointed the right place . I will try again to set this QFrame translucent background no luck

shenlebantongying commented 1 year ago

Chrome with the Dark Reader extension doesn't solve the "white flash". Using a light theme, chrome will have the same kind of white flash. So there is no solution within chromium.

The QWebEnginePage.setBackground() only changes the initial background, and it does not affect the Chromium's background when loading a page.

So, I think hiding when the articleview during page loading is the best fix.

xiaoyifang commented 1 year ago

https://bugreports.qt.io/browse/QTBUG-67434

xiaoyifang commented 1 year ago

957

Canvis-Me commented 1 year ago

这个和深色模式没关系,只要背景不是白的就会闪一下白色,比如文章显示风格换为经典也是会闪白色。

github-actions[bot] commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.

This has nothing to do with the dark mode, as long as the background is not white, it will flash white. For example, if the "article display style" is changed to "classic", it will also flash white.

seth-js commented 10 months ago

Any update to this? Having the same issue as #957.

xiaoyifang commented 10 months ago

use the latest pre-release version . the possibility of white-flash has been reduced.

seth-js commented 10 months ago

That fixed the issue for me. Thank you.