Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to properly remove icons from menus (for a cleaner UX) #3230

Merged
merged 17 commits into from
Feb 11, 2025

Conversation

andrei-a-papou
Copy link
Contributor

Hi, and thank you for creating QOwnNotes. I've been using it for a couple of weeks now (migrated from a legacy note-taking app) and it looks very impressive so far! Packed with features, very customizable and scriptable.

I'm using it on a mostly GTK-based Linux desktop where menus do not have icons and would like to have the same option in QOwnNotes for a cleaner user experience.

I'm very new to Qt and it took some research to properly remove the icons.

First, I've tried to do it the way macOSX icons are removed in the QOwnNotes code-base (Qt::AA_DontShowIconsInMenus), but this method leaves empty spaces in place of the icons (at least on Linux), which doesn't look good at all, IMO.

Another option is to simply iterate over all the actions and set icons to null. This removes the icons and the empty space, but kill icons in toolbars too.

After experimenting, I've found that the best way is to use QProxyStyle. Hence this patch.

I'm not interested in maintaining my own fork :), so would appreciate it if you could merge it on your end. I've noticed some other little bugs/quirks here and there. I'll try to report them soon as time permits.

Overall, QOwnNotes looks like a great app with a ton of useful features. So thank you again for creating it and let me know if the patch can be merged.

@pbek
Copy link
Owner

pbek commented Feb 10, 2025

There already is a rule for macOS 🤔:

#ifdef Q_OS_MAC
// disable icons in the menu
QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, true);
#endif

We need to do something about that too...

@andrei-a-papou
Copy link
Contributor Author

andrei-a-papou commented Feb 10, 2025

There already is a rule for macOS 🤔:

I don't have a way to test things on a Mac, but would it be OK to limit the patch to Linux and Windows via #ifdef and such? The existing Mac logic can stay the way it is. Or it can be removed (but unfortunately I wouldn't be able to test the result on a Mac.)

So my suggestion would be to limit the patch to Windows and Linux only. Your thoughts?

@pbek
Copy link
Owner

pbek commented Feb 10, 2025

First one other question: Why was QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, true); not enough for your use-case?

Seems to work fine under Linux. The command bar is extra of course.

I guess it would be best to stick to QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, true); and just set the default for your setting to be true for macOS by default. Of course, the settings reading needs to go into a method then, like so:

QOwnNotes/src/utils/misc.cpp

Lines 1299 to 1301 in a1c7a31

bool Utils::Misc::isNoteEditingAllowed() {
return SettingsService().value(QStringLiteral("allowNoteEditing"), true).toBool();
}

@andrei-a-papou
Copy link
Contributor Author

andrei-a-papou commented Feb 10, 2025

First one other question: Why was QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, true); not enough for your use-case?

No, not enough, that's the whole point. The Qt::AA_DontShowIconsInMenus removes the icons, but leaves a lot of ugly empty space where the icons used to be. IMO, this makes the menus look worse, not better, especially if the menu contains checkboxes.

Not only do the empty spaces look bad, they also make the menus with hidden icons look different from other menus that are icon-less by design, for example, the Toolbars menu. This inconsistency IMO would make the UI look less professional than it could be :)

@pbek
Copy link
Owner

pbek commented Feb 10, 2025

just set the default for your setting to be true for macOS by default. Of course, the settings reading needs to go into a method then

ok, then still ☝🏻 and the builds are still failing, because of the duplicate declaration (how did the build work for you? 🤔)

@andrei-a-papou
Copy link
Contributor Author

just set the default for your setting to be true for macOS by default. Of course, the settings reading needs to go into a method then

ok, then still ☝🏻 and the builds are still failing, because of the duplicate declaration (how did the build work for you?

You're right. The build worked for me because the patch I provided depends on another patch (not included here for now).

Fixed it here. It now compiles on my end when I do a clean qmake && make from the github source tree.

@andrei-a-papou
Copy link
Contributor Author

@pbek Some builds failed due to undefined reference to `vtable for NoMenuIconStyle', which is fixed now.

@pbek
Copy link
Owner

pbek commented Feb 10, 2025

Please use lower case characters for NoMenuIconStyle.* and move the files to the src/helpers folder.
Please also add the two files to src/CMakeLists.txt.
And please run ./scripts/clang-format-project.sh on your changes...

* @return
*/
bool Utils::Misc::hideIconsInMenus() {
return SettingsService().value(QStringLiteral("hideIconsInMenus"), true).toBool();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default needs to be true for macOS and false for all other operating systems. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm now setting the default here: 259c49f

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could instead of setting true just use a variable that is set to false and set it to true with a compiler directive for macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't quite follow... Do you mean we shouldn't use if (!settings.contains(QStringLiteral("hideIconsInMenus"))) { ... }? if so, why?

I'm new to Qt and the code-base, so if you think there's a better way to do the macOS check, please feel free to give it a quick edit :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/main.cpp Outdated
}

#ifdef Q_OS_MAC
QApplication::setStyle(new NoMenuIconStyle);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than forcing the style for macOS, please use your new setting instead and set a proper default value in your hideIconsInMenus method.

Copy link
Contributor Author

@andrei-a-papou andrei-a-papou Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, no forcing, but can we just set a default like I did here? 259c49f

I've tested it under Linux with #ifdef Q_OS_LINUX instead of #ifdef Q_OS_MAC and it seems to work fine.

When no setting has been defined, the app hides icons on macOS. If a user ticks the checkbox, the app reads that setting instead.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was talking about a variable for the default value, like here:

#ifdef Q_OS_MAC
bool restoreCursorPositionDefault = false;
#else
bool restoreCursorPositionDefault = true;
#endif
ui->restoreCursorPositionCheckBox->setChecked(
settings.value(QStringLiteral("restoreCursorPosition"), restoreCursorPositionDefault)
.toBool());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, how about this? 7f7cc8c

@andrei-a-papou
Copy link
Contributor Author

Please use lower case characters for NoMenuIconStyle.* and move the files to the src/helpers folder. Please also add the two files to src/CMakeLists.txt. And please run ./scripts/clang-format-project.sh on your changes...

Renamed and moved the files, but the clang-format-project.sh doesn't work on my machine. This is the output of clang-format --version:

clang-format --version
Debian clang-format version 11.0.1-2

Running the script produces a bunch of "not found" errors...

@pbek
Copy link
Owner

pbek commented Feb 10, 2025

Debian clang-format version 11.0.1-2

omg, I'm, at clang-format version 19.1.5

@andrei-a-papou
Copy link
Contributor Author

Debian clang-format version 11.0.1-2

omg, I'm, at clang-format version 19.1.5

Can you please run the script then?


SettingsService settings;

if (!settings.contains(QStringLiteral("hideIconsInMenus"))) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need that whole if-clause, because there is no old setting to migrate from.

@pbek pbek merged commit da690c2 into pbek:main Feb 11, 2025
32 of 33 checks passed
@pbek
Copy link
Owner

pbek commented Feb 11, 2025

Oh, there is something important that slipped my review:

QOwnNotes/src/main.cpp

Lines 192 to 201 in da690c2

// restore the interface style
if (!interfaceStyle.isEmpty()) {
QApplication::setStyle(interfaceStyle);
}
// apply custom style to hide menu icons
const bool hideMenuIcons = Utils::Misc::areMenuIconsHidden();
if (hideMenuIcons) {
QApplication::setStyle(new NoMenuIconStyle);
}

You are breaking the interface style setting with your QApplication::setStyle!

pbek added a commit that referenced this pull request Feb 11, 2025
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@pbek
Copy link
Owner

pbek commented Feb 11, 2025

I'll disable your QApplication::setStyle(new NoMenuIconStyle); in favor for QApplication::setAttribute(Qt::AA_DontShowIconsInMenus, true); for now until you come up with a different idea.

But I still can't see a difference between the two in the menu. 🤔 Could you maybe provide screenshots where you see a difference on your system?

pbek added a commit that referenced this pull request Feb 11, 2025
…erfaceStyle settting

Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
pbek added a commit that referenced this pull request Feb 11, 2025
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
pbek added a commit that referenced this pull request Feb 11, 2025
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@andrei-a-papou
Copy link
Contributor Author

I'll disable your QApplication::setStyle(new NoMenuIconStyle); in favor for QApplication::setAttribute(Qt::AA_DontShowIconsInMenus, true); for now until you come up with a different idea.

This is very frustrating, I'm sorry to say :) Because now it looks broken...

But I still can't see a difference between the two in the menu. 🤔 Could you maybe provide screenshots where you see a difference on your system?

Sure. The first screenshot uses Qt::AA_DontShowIconsInMenus.

image

The second screenshot uses the PR that actually deals with the problem:

image

@pbek
Copy link
Owner

pbek commented Feb 11, 2025

No difference for under KDE Plasma...

QApplication::setAttribute(Qt::AA_DontShowIconsInMenus, true);

image

QApplication::setStyle(new NoMenuIconStyle);

image

@pbek
Copy link
Owner

pbek commented Feb 11, 2025

Maybe you can find a solution, that will still keep the interfaceStyle setting.

@andrei-a-papou
Copy link
Contributor Author

It's interesting that Qt::AA_DontShowIconsInMenus works under KDE Plasma. Maybe it's a Qt5 vs Qt6 thing, who knows, but I know for sure I'm not the only one having this problem: https://stackoverflow.com/questions/44745459/remove-icon-space-from-qmenu

Would you accept a patch that relies on NoMenuIconStyle, but enables the option to hide icons only if "Interface style" is set to Automatic? (macOS can use Qt::AA_DontShowIconsInMenus like before.)

@pbek
Copy link
Owner

pbek commented Feb 12, 2025

Would you accept a patch that relies on NoMenuIconStyle, but enables the option to hide icons only if "Interface style" is set to Automatic?

That would be an option, but you need to keep in mind that the interfaceStyle setting is applied dynamically while the setting dialog is opened and when the selectbox in the dialog changes!

The better solution would be if your style could somehow inherit the interfaceStyle, maybe like in the example from https://doc.qt.io/qt-6/qapplication.html#setStyle.

(macOS can use Qt::AA_DontShowIconsInMenus like before.)

I guess macOS can use the same handling as above...

@andrei-a-papou
Copy link
Contributor Author

The better solution would be if your style could somehow inherit the interfaceStyle

Thanks for the pointer. Right now time does not permit me to work on any more patches, but maybe in the future. Good luck!

@pbek
Copy link
Owner

pbek commented Feb 12, 2025

Thank you, and thank you for your contribution!

@pbek
Copy link
Owner

pbek commented Feb 12, 2025

25.2.4

  • There now is a setting to hide the icons in the main menu and command bar in the Interface settings
    (for #3230, thank you, @andrei-a-papou)

There now is a new release, could you please test it and report if it works for you?

pbek added a commit that referenced this pull request Feb 12, 2025
…erfaceStyle setting

Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@pbek
Copy link
Owner

pbek commented Feb 12, 2025

Can you please also test the latest main branch with 854a3ab, where I tried to make interfaceStyle work with NoMenuIconStyle?

Can you please test different interfaceStyle settings with hideIconsInMenus set to true and false?

pbek added a commit that referenced this pull request Feb 12, 2025
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@andrei-a-papou
Copy link
Contributor Author

andrei-a-papou commented Feb 12, 2025

Can you please also test the latest main branch with 854a3ab, where I tried to make interfaceStyle work with NoMenuIconStyle?

Can you please test different interfaceStyle settings with hideIconsInMenus set to true and false?

The 854a3ab commit works fine, I tested with the "Automatic" setting for style (which happens to be Kvantum on my box), as well as "motif", "windows" and "plastique" styles. Awesome!

I've tried with "hideIconsInMenus" on and off.

There's one hiccup: with "hideIconsInMenus" on, if a user changes the interface style, the style is applied, but the menu icons reappear until the app is restarted. Seems like prompting for a restart after changing the interface style would make everything work perfectly.

Will be happy to test.

P. S. Incidentally, I now remember playing with interface styles when I first installed QOwnNotes, and I think the styles did not always perfectly applied unless I restarted the app. Seems like it's a good idea to prompt for a restart when changing a style anyway.

@pbek
Copy link
Owner

pbek commented Feb 13, 2025

There's one hiccup: with "hideIconsInMenus" on, if a user changes the interface style, the style is applied, but the menu icons reappear until the app is restarted. Seems like prompting for a restart after changing the interface style would make everything work perfectly.

Hah, didn't catch my eyes. Thank you for mentioning. Forgot a stray QApplication::setStyle(). I'll fix that.

P. S. Incidentally, I now remember playing with interface styles when I first installed QOwnNotes, and I think the styles did not always perfectly applied unless I restarted the app. Seems like it's a good idea to prompt for a restart when changing a style anyway.

QApplication::setStyle() is supposed to work instantly.
But now they are applying instantly for you too?

@andrei-a-papou
Copy link
Contributor Author

QApplication::setStyle() is supposed to work instantly.
But now they are applying instantly for you too?

Yes. Everything works as expected, except the hiccup I mentioned above.

@pbek
Copy link
Owner

pbek commented Feb 13, 2025

Yes. Everything works as expected, except the hiccup I mentioned above.

Ok, great. I'll fix the hiccup in the evening.

pbek added a commit that referenced this pull request Feb 13, 2025
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@pbek
Copy link
Owner

pbek commented Feb 13, 2025

25.2.5

  • The main menu and command bar now has a cleaner user experience when icons are hidden
    on GTK-based Linux desktops (for #3230)

There now is a new release, could you please test it and report if it works for you?

@andrei-a-papou
Copy link
Contributor Author

@pbek Works nicely now, thank you!

@pbek
Copy link
Owner

pbek commented Feb 14, 2025

Great, thank you for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants