Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Showcase
  4. Review for my svg icon library
QtWS25 Last Chance

Review for my svg icon library

Scheduled Pinned Locked Moved Showcase
svgicon
11 Posts 5 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hellorge
    wrote on 27 Jul 2024, 15:32 last edited by Hellorge
    #1

    Hello everyone,

    I’m new here and also new to Qt and C++.

    I’ve been working on a new to-do app just for fun. As an experienced web developer, SVGs were my default choice for icons. However, I found Qt’s support for SVGs to be lacking. So, I decided to extend the support myself, and that’s how I started working on QtSvgIconEngine.

    This project allows you to link all SVG files to your project and then use them as icons with various color and option settings. While it’s still a work in progress—icon animations and transitions are yet to be implemented—I wanted to showcase it and get some feedback.

    Apologies in advance if I made any mistakes posting this here. Thank you!

    1 Reply Last reply
    0
    • H Hellorge marked this topic as a regular topic on 27 Jul 2024, 15:55
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 27 Jul 2024, 18:26 last edited by
      #2

      Hi and welcome to devnet,

      No problem with posting such things here.

      IIRC, there's currently an effort to modernize a bit the QtSvg module, you might want to take a look there. There might be some stuff you could help doing :-)

      That said, for your own code, you should consider using QLoggingCategory. You might also want to handle your error message as error and not warning. It feels a bit counterintuitive to see logError that prints a warning. Also, why make the SvgIcon class a QObject ? It seems to be a bit overkill since it's not using any QObject feature. You also lose the possibility to copy the class.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      H 1 Reply Last reply 27 Jul 2024, 19:49
      1
      • S SGaist
        27 Jul 2024, 18:26

        Hi and welcome to devnet,

        No problem with posting such things here.

        IIRC, there's currently an effort to modernize a bit the QtSvg module, you might want to take a look there. There might be some stuff you could help doing :-)

        That said, for your own code, you should consider using QLoggingCategory. You might also want to handle your error message as error and not warning. It feels a bit counterintuitive to see logError that prints a warning. Also, why make the SvgIcon class a QObject ? It seems to be a bit overkill since it's not using any QObject feature. You also lose the possibility to copy the class.

        H Offline
        H Offline
        Hellorge
        wrote on 27 Jul 2024, 19:49 last edited by Hellorge
        #3

        @SGaist Thank you for your feedback.

        QLoggingCategory seems very useful,
        SvgIcon is a QObject because next step is to add animations and transitions to the icon and it'll be beneficial to emit signals when things animate or let's say properties like color and size changes. SvgIcon class for now is like a placeholder, possibilities exist that I use QSvgWidget and QGraphicsSvgItem to completely convert a svg file's contents into Qt objects and work with them.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 28 Jul 2024, 18:34 last edited by
          #4

          You might want to rethink the naming of the classes then. They are a bit too close to their counterpart currently and change significantly in terms of usage if you take for example QIcon.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          H 1 Reply Last reply 29 Jul 2024, 10:00
          0
          • S SGaist
            28 Jul 2024, 18:34

            You might want to rethink the naming of the classes then. They are a bit too close to their counterpart currently and change significantly in terms of usage if you take for example QIcon.

            H Offline
            H Offline
            Hellorge
            wrote on 29 Jul 2024, 10:00 last edited by Hellorge
            #5

            @SGaist Hello,

            I understand your point but personally I don't find naming to be an issue, if possible can you suggest better naming options?

            Also, SvgIcon class now inherits QSvgWidget and supports animations for color, size, image-scale and opacity. I have been thinking about seperating animations and heavier stuff into an addon which can be enabled when initiating SvgIconEngine instead of always being present with all SvgIcon instances. This can simply make it less heavier for cases when simple static icons are required without any post generation animation support.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 29 Jul 2024, 10:03 last edited by
              #6

              Hi, nice project, good luck!

              One small suggestion: if you want others to use it and contribute, you should include a license text in the repository. Without a license, nobody can (legally) use your code.

              Some nice license candidates are: MIT license, GPL, LGPL, WTFPL.

              (Z(:^

              H 1 Reply Last reply 29 Jul 2024, 10:15
              0
              • S sierdzio
                29 Jul 2024, 10:03

                Hi, nice project, good luck!

                One small suggestion: if you want others to use it and contribute, you should include a license text in the repository. Without a license, nobody can (legally) use your code.

                Some nice license candidates are: MIT license, GPL, LGPL, WTFPL.

                H Offline
                H Offline
                Hellorge
                wrote on 29 Jul 2024, 10:15 last edited by Hellorge
                #7

                @sierdzio Thank you, the repo is now under GPLv3 LGPL license.

                S 1 Reply Last reply 29 Jul 2024, 19:23
                1
                • H Hellorge
                  29 Jul 2024, 10:15

                  @sierdzio Thank you, the repo is now under GPLv3 LGPL license.

                  S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 29 Jul 2024, 19:23 last edited by
                  #8

                  @Hellorge for the class names, I would recommend following the class you are subclassing with maybe your own prefix.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    SimonSchroeder
                    wrote on 30 Jul 2024, 06:22 last edited by
                    #9

                    There is currently one problem with using SVG icons in Qt: I have two monitors with different display scaling. Our software uses SVG icons for the QToolButtons in the QToolBar. Moving the main window from one screen to the other rescales everything. We react to the event and then recreate all tool bars so they have the correct pixel size for the SVG. Maybe with what you are doing you can come up with a solution that works automatically, i.e. if the tool button resizes the icon (based on a SVG) also resizes.

                    H C 2 Replies Last reply 4 Aug 2024, 14:46
                    0
                    • S SimonSchroeder
                      30 Jul 2024, 06:22

                      There is currently one problem with using SVG icons in Qt: I have two monitors with different display scaling. Our software uses SVG icons for the QToolButtons in the QToolBar. Moving the main window from one screen to the other rescales everything. We react to the event and then recreate all tool bars so they have the correct pixel size for the SVG. Maybe with what you are doing you can come up with a solution that works automatically, i.e. if the tool button resizes the icon (based on a SVG) also resizes.

                      H Offline
                      H Offline
                      Hellorge
                      wrote on 4 Aug 2024, 14:46 last edited by Hellorge 8 Apr 2024, 15:41
                      #10

                      @SimonSchroeder
                      Surely, minor issues like this will be addressed, but right now I'm stuck at converting my Icon class (SvgIcon inherits QSvgWidget) to QIcon, or simply put it can't be used at places expecting a QIcon, I have minor grasp of inheriting QIconEngine and using SvgIcons as source for painting, but I'm not sure about some other better approach or let's say reworking things already set to get a better solution. Any suggestions would be appreciated.

                      Well a quick update on this:

                      SvgIconEngine iconEngine(":/icons");
                      SvgIcon *icon = iconEngine.getIcon("regular", "flag");
                      
                      QPushButton *btn = new QPushButton(icon->toQIcon(), "");
                      //toQIcon: QImage -> QPixmap -> QIcon
                      
                      QObject::connect(icon, &SvgIcon::iconChanged, [=]() {
                          btn->setIcon(icon->toQIcon());
                          btn->update();
                      });
                      

                      with this approach I still face issues like size and opacity stop animating on QPushButton, will look for a better solution.

                      1 Reply Last reply
                      0
                      • S SimonSchroeder
                        30 Jul 2024, 06:22

                        There is currently one problem with using SVG icons in Qt: I have two monitors with different display scaling. Our software uses SVG icons for the QToolButtons in the QToolBar. Moving the main window from one screen to the other rescales everything. We react to the event and then recreate all tool bars so they have the correct pixel size for the SVG. Maybe with what you are doing you can come up with a solution that works automatically, i.e. if the tool button resizes the icon (based on a SVG) also resizes.

                        C Offline
                        C Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 4 Aug 2024, 14:57 last edited by
                        #11

                        @SimonSchroeder I doubt this library can help here. Can you please provide a minimal, compilable example in a bug report? I can take a look on it. Sounds similar to https://bugreports.qt.io/browse/QTBUG-122403 which needs a QIcon instead a QPixmap to make scaling work for your situation.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0

                        7/11

                        29 Jul 2024, 10:15

                        • Login

                        • Login or register to search.
                        7 out of 11
                        • First post
                          7/11
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved