Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why not use native widgets?
Forum Updated to NodeBB v4.3 + New Features

Why not use native widgets?

Scheduled Pinned Locked Moved Unsolved General and Desktop
36 Posts 5 Posters 5.6k Views 3 Watching
  • 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.
  • Chris KawaC Chris Kawa

    @brainchild Like I said, when using low level API each control is its own window. It's an OS allocated object the app gets a handle to (HWND on windows). Each interaction with that object is a system level call. Having a large amount of these objects is slow, heavy and very memory consuming.
    Qt doesn't create any such objects. It uses APIs like DrawThemeBackgroundEx to just "paint a picture" of a control on its surface. It doesn't require allocating resources or keeping system objects around. It's a lot lighter approach.
    As for drawing offscreen or directly to window - Before Qt 4.4 drawing was done directly and it had massive issues with refresh and flicker, especially on resize. Qt 4.4 introduced a concept of native and alien widgets. Alien widgets would draw to that offscreen buffer while native ones would get their own window. By default only top level widgets are native now and everything inside is alien. If you need you can force a widget to become native like I mentioned above, with winId(), but it has performance penalty attached.

    B Offline
    B Offline
    brainchild
    wrote on last edited by brainchild
    #14

    @Chris-Kawa said in Why not use native widgets?:

    It uses APIs like DrawThemeBackgroundEx to just "paint a picture" of a control on its surface. It doesn't require allocating resources or keeping system objects around. It's a lot lighter approach.

    There is no allocation of external, stateful resources? I have never seen such a use of widgets. How would they respond to events?

    Before Qt 4.4 drawing was done directly and it had massive issues with refresh and flicker, especially on resize.

    Why would it be different than the case of applications built directly on the platform tool chain?

    Chris KawaC W 2 Replies Last reply
    0
    • B brainchild

      @Chris-Kawa said in Why not use native widgets?:

      It uses APIs like DrawThemeBackgroundEx to just "paint a picture" of a control on its surface. It doesn't require allocating resources or keeping system objects around. It's a lot lighter approach.

      There is no allocation of external, stateful resources? I have never seen such a use of widgets. How would they respond to events?

      Before Qt 4.4 drawing was done directly and it had massive issues with refresh and flicker, especially on resize.

      Why would it be different than the case of applications built directly on the platform tool chain?

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #15

      @brainchild said:

      There is no allocation of external, stateful resources?

      There might be some state allocated by the platform plugin here and there, but there's no per widget OS level objects. Widgets are Qt objects. Only painting them makes these light API calls that don't require persistent state.

      I have never seen such a use of widgets

      All widgets work like that. If you've seen a widget you've seen it working like that.

      How would they respond to events?

      There are two types of events - OS level events like input, resizing etc. and internal Qt events. OS level events are sent to a window (remember - top level widget is native) via messages. Qt translates them into Qt counterparts and dispatches them to appropriate widgets. For example a QPushButton doesn't deal with system level messages like WM_LBUTTONDOWN. Those are sent to the window and Qt translates them into QEvent::MouseButtonPress and the button gets it in this platform agnostic form.

      Why would it be different than the case of applications built directly on the platform tool chain?

      It's not. Like I mentioned above - a lot of old applications built this way look and behave terribly. Modern apps use one of these other technologies I mentioned, which mostly do the same as Qt does - bypass the low level API.

      B 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        @brainchild said:

        There is no allocation of external, stateful resources?

        There might be some state allocated by the platform plugin here and there, but there's no per widget OS level objects. Widgets are Qt objects. Only painting them makes these light API calls that don't require persistent state.

        I have never seen such a use of widgets

        All widgets work like that. If you've seen a widget you've seen it working like that.

        How would they respond to events?

        There are two types of events - OS level events like input, resizing etc. and internal Qt events. OS level events are sent to a window (remember - top level widget is native) via messages. Qt translates them into Qt counterparts and dispatches them to appropriate widgets. For example a QPushButton doesn't deal with system level messages like WM_LBUTTONDOWN. Those are sent to the window and Qt translates them into QEvent::MouseButtonPress and the button gets it in this platform agnostic form.

        Why would it be different than the case of applications built directly on the platform tool chain?

        It's not. Like I mentioned above - a lot of old applications built this way look and behave terribly. Modern apps use one of these other technologies I mentioned, which mostly do the same as Qt does - bypass the low level API.

        B Offline
        B Offline
        brainchild
        wrote on last edited by
        #16

        @Chris-Kawa said in Why not use native widgets?:

        Those are sent to the window and Qt translates them into QEvent::MouseButtonPress and the button gets it in this platform agnostic form.

        Right, but the appearance of the pressed button is created by a resource that knows its a button with certain properties that has received a mouse-down event, and now considers itself pressed, right? Widgets are intrinsically stateful resources that may change their own state based on events (or properties being set externally), right?

        Chris KawaC 1 Reply Last reply
        0
        • B brainchild

          @Chris-Kawa said in Why not use native widgets?:

          Those are sent to the window and Qt translates them into QEvent::MouseButtonPress and the button gets it in this platform agnostic form.

          Right, but the appearance of the pressed button is created by a resource that knows its a button with certain properties that has received a mouse-down event, and now considers itself pressed, right? Widgets are intrinsically stateful resources that may change their own state based on events (or properties being set externally), right?

          Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #17

          @brainchild Yes, but the state is held by the widget, which is a Qt object, platform agnostic, internal to your process and invisible to the system. When time comes to paint a widget its state is turned into the appropriate parameters to that system API call. Other than that the OS knows nothing about the existence of that widget.
          A low level API in contrast uses system objects for each control and holds state in these objects.
          If you use a tool like Spy++ you'll see that to the OS Qt app is just a singular blank window, where if you code entire app in system objects you can inspect each and every control separately.

          B 1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            @brainchild Yes, but the state is held by the widget, which is a Qt object, platform agnostic, internal to your process and invisible to the system. When time comes to paint a widget its state is turned into the appropriate parameters to that system API call. Other than that the OS knows nothing about the existence of that widget.
            A low level API in contrast uses system objects for each control and holds state in these objects.
            If you use a tool like Spy++ you'll see that to the OS Qt app is just a singular blank window, where if you code entire app in system objects you can inspect each and every control separately.

            B Offline
            B Offline
            brainchild
            wrote on last edited by
            #18

            @Chris-Kawa said in Why not use native widgets?:

            When time comes to paint a widget its state is turned into the appropriate parameters to that system API call.

            That is surprising. Without internal state for the widget, it cannot determine its own behavior by way of internal transition, or process events by its own handlers. Meanwhile, a widget will often need to paint itself only partially, for example, due to the removal of an incomplete occlusion, and an ability to resolve an optimization might provide value in certain cases.

            Chris KawaC 1 Reply Last reply
            0
            • B brainchild

              @Chris-Kawa said in Why not use native widgets?:

              It uses APIs like DrawThemeBackgroundEx to just "paint a picture" of a control on its surface. It doesn't require allocating resources or keeping system objects around. It's a lot lighter approach.

              There is no allocation of external, stateful resources? I have never seen such a use of widgets. How would they respond to events?

              Before Qt 4.4 drawing was done directly and it had massive issues with refresh and flicker, especially on resize.

              Why would it be different than the case of applications built directly on the platform tool chain?

              W Offline
              W Offline
              wrosecrans
              wrote on last edited by
              #19

              @brainchild said in Why not use native widgets?:

              Why would it be different than the case of applications built directly on the platform tool chain?

              Lots of applications written in raw Win32 have flicker issues. It isn't a difference.

              1 Reply Last reply
              0
              • B brainchild

                @Chris-Kawa said in Why not use native widgets?:

                When time comes to paint a widget its state is turned into the appropriate parameters to that system API call.

                That is surprising. Without internal state for the widget, it cannot determine its own behavior by way of internal transition, or process events by its own handlers. Meanwhile, a widget will often need to paint itself only partially, for example, due to the removal of an incomplete occlusion, and an ability to resolve an optimization might provide value in certain cases.

                Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by Chris Kawa
                #20

                @brainchild said:

                Without internal state for the widget, it cannot determine its own behavior by way of internal transition

                A QWidget is an application side object. It does hold and has access to its own state. It does process Qt events synthetized from native messages and dispatched to it by Qt. It does not create a system object. It does not process native system messages. It only uses stateless system API to draw itself.

                In an app using low level native API a widget would not hold its own state or have a cross-platform event handling solution. It would only hold a handle to a native object that holds the state and handles native messages. This is not what's happening here.

                Meanwhile, a widget will often need to paint itself only partially

                A paintEvent of a widget has a QPaintEvent* parameter that passes such information. One of them is the rectangular area that needs update. It doesn't have to cover entire widget if only partial change happened. The implementation of the paintEvent has an opportunity for optimization here if full update is not required.

                B 1 Reply Last reply
                0
                • Chris KawaC Chris Kawa

                  @brainchild said:

                  Without internal state for the widget, it cannot determine its own behavior by way of internal transition

                  A QWidget is an application side object. It does hold and has access to its own state. It does process Qt events synthetized from native messages and dispatched to it by Qt. It does not create a system object. It does not process native system messages. It only uses stateless system API to draw itself.

                  In an app using low level native API a widget would not hold its own state or have a cross-platform event handling solution. It would only hold a handle to a native object that holds the state and handles native messages. This is not what's happening here.

                  Meanwhile, a widget will often need to paint itself only partially

                  A paintEvent of a widget has a QPaintEvent* parameter that passes such information. One of them is the rectangular area that needs update. It doesn't have to cover entire widget if only partial change happened. The implementation of the paintEvent has an opportunity for optimization here if full update is not required.

                  B Offline
                  B Offline
                  brainchild
                  wrote on last edited by
                  #21

                  @Chris-Kawa

                  What you are describing is Qt interpreting low-level input as high-level state changes for the widget, then expressing those changes into stateless calls of the widget rendering engine. The result is that Qt is the gatekeeper of which real effects (e.g. left mouse button pressed and held longer than 300 ms) represent which high-level state changes (e.g. the button entering a pressed state from unpressed). The button cannot express itself, through a life of its own, by hearing the mouse events and deciding when to explain that it has entered into a pressed state and that specific regions within itself need to be refreshed. Augmentation or refinement within the platform toolkit is not possible. Meanwhile, repainting occurs only when requested by Qt, and only from scratch. It is not helpful that the repaint call may constrain a region for the widget to determine which regions it determines have change based on its own analysis of internal internal state.

                  Chris KawaC 1 Reply Last reply
                  0
                  • B brainchild

                    @Chris-Kawa

                    What you are describing is Qt interpreting low-level input as high-level state changes for the widget, then expressing those changes into stateless calls of the widget rendering engine. The result is that Qt is the gatekeeper of which real effects (e.g. left mouse button pressed and held longer than 300 ms) represent which high-level state changes (e.g. the button entering a pressed state from unpressed). The button cannot express itself, through a life of its own, by hearing the mouse events and deciding when to explain that it has entered into a pressed state and that specific regions within itself need to be refreshed. Augmentation or refinement within the platform toolkit is not possible. Meanwhile, repainting occurs only when requested by Qt, and only from scratch. It is not helpful that the repaint call may constrain a region for the widget to determine which regions it determines have change based on its own analysis of internal internal state.

                    Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #22

                    @brainchild I don't really see where you get those ideas from. I'm kinda lost what are we discussing here. Are you asking something or suggesting? I'm not sure what you want me to do.

                    As for how it works. An example of what happens when you click a button:

                    • User presses a mouse button and OS sends a message WM_LBUTTONDOWN with global mouse position.
                    • Qt translates that into QEvent::MouseButtonPress, looks up widget at given coords and posts a QMouseEvent to that widget
                    • Widget executes a mousePressEvent(QMouseEvent*) handler. In it a pressed state is determined and stored.
                    • Since the state changed widget requests an update(). This marks it dirty and schedules a repaint.
                    • Widget executes a paintEvent(QPaintEvent*) handler in which it calls the platform plugin abstraction to paint its state. If it's animated or anything like that it can start the animation, timers, schedule further updates or whatever it needs.
                    • If some further updates were scheduled widget executes further paintEvent(QPaintEvent*) handlers.
                    • At some point (3s or 300ms later, doesn't matter) user releases the button and OS sends WM_LBUTTONUP
                    • Qt translates that into QEvent::MouseButtonRelease and posts another QMouseEvent to the widget.
                    • Widget executes a mouseReleaseEvent(QMouseEvent*) handler. In it the pressed state is terminated and new state stored.
                    • Since both press and release occurred widget emits a clicked() signal.
                    • Since the state changed widget requests an update(). This marks it dirty and schedules a repaint.
                    • Widget executes a paintEvent(QPaintEvent*) handler in which it calls the platform plugin abstraction to paint its new state. Other housekeeping can be performed here e.g terminating animations.
                    • and so on...

                    Maybe you should just read the Qt's code if you're interested in such details?

                    B 1 Reply Last reply
                    1
                    • Chris KawaC Chris Kawa

                      @brainchild I don't really see where you get those ideas from. I'm kinda lost what are we discussing here. Are you asking something or suggesting? I'm not sure what you want me to do.

                      As for how it works. An example of what happens when you click a button:

                      • User presses a mouse button and OS sends a message WM_LBUTTONDOWN with global mouse position.
                      • Qt translates that into QEvent::MouseButtonPress, looks up widget at given coords and posts a QMouseEvent to that widget
                      • Widget executes a mousePressEvent(QMouseEvent*) handler. In it a pressed state is determined and stored.
                      • Since the state changed widget requests an update(). This marks it dirty and schedules a repaint.
                      • Widget executes a paintEvent(QPaintEvent*) handler in which it calls the platform plugin abstraction to paint its state. If it's animated or anything like that it can start the animation, timers, schedule further updates or whatever it needs.
                      • If some further updates were scheduled widget executes further paintEvent(QPaintEvent*) handlers.
                      • At some point (3s or 300ms later, doesn't matter) user releases the button and OS sends WM_LBUTTONUP
                      • Qt translates that into QEvent::MouseButtonRelease and posts another QMouseEvent to the widget.
                      • Widget executes a mouseReleaseEvent(QMouseEvent*) handler. In it the pressed state is terminated and new state stored.
                      • Since both press and release occurred widget emits a clicked() signal.
                      • Since the state changed widget requests an update(). This marks it dirty and schedules a repaint.
                      • Widget executes a paintEvent(QPaintEvent*) handler in which it calls the platform plugin abstraction to paint its new state. Other housekeeping can be performed here e.g terminating animations.
                      • and so on...

                      Maybe you should just read the Qt's code if you're interested in such details?

                      B Offline
                      B Offline
                      brainchild
                      wrote on last edited by brainchild
                      #23

                      @Chris-Kawa

                      Let's make it simple, even if it means being silly.

                      Suppose the next version of the platform's widget toolkit is changed such that every button will change its text color every 10 seconds, automatically, following a round-robin selection of six colors. If a button is allocated as a system resource, then it may implement this behavior by setting a timer for 10 seconds, and when receiving a callback, change its internal state for the new color, and then notify that the region containing its text is has become invalid. Such behavior cannot occur, from what I understand, through Qt, because Qt does not recognize the particular internal behavior as a feature of the widget. The widget state and events are only that which Qt keeps and follows, based on its generic, system-agnostic understanding of a button, which does not include the timer, repainting, or color selection, which a system resource could manage itself.

                      Surely there are non-silly, and quite real, examples of such limitations.

                      Has my presentation exposed some misunderstanding?

                      Chris KawaC 1 Reply Last reply
                      0
                      • B brainchild

                        @Chris-Kawa

                        Let's make it simple, even if it means being silly.

                        Suppose the next version of the platform's widget toolkit is changed such that every button will change its text color every 10 seconds, automatically, following a round-robin selection of six colors. If a button is allocated as a system resource, then it may implement this behavior by setting a timer for 10 seconds, and when receiving a callback, change its internal state for the new color, and then notify that the region containing its text is has become invalid. Such behavior cannot occur, from what I understand, through Qt, because Qt does not recognize the particular internal behavior as a feature of the widget. The widget state and events are only that which Qt keeps and follows, based on its generic, system-agnostic understanding of a button, which does not include the timer, repainting, or color selection, which a system resource could manage itself.

                        Surely there are non-silly, and quite real, examples of such limitations.

                        Has my presentation exposed some misunderstanding?

                        Chris KawaC Offline
                        Chris KawaC Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on last edited by Chris Kawa
                        #24

                        @brainchild Yes, it's a limitation, but not very important in practice. The situation you describe doesn't happen very often. A lot of windowing frameworks work like that, not just Qt, and OS manufacturers don't have any real incentive to break most applications look with new releases. They rather go out of their way not to do that, even when they change the look and feel. Windows APIs and behavior for example haven't changed since Windows XP (over 20 years). The look of the controls changed, some colors maybe, but not the fundamental mechanic. If it happens Qt can just update its platform plugin. The current one didn't need updating for a long time (it's still called WindowsVistaStyle if I'm not mistaken).

                        If you don't like that limitation anyway, you can provide your own platform plugin that will instantiate a bunch of system objects and get rid of that limitation that way. It's a plugin, so it's flexible. Can be updated independently or entirely replaced.

                        B 1 Reply Last reply
                        0
                        • Chris KawaC Chris Kawa

                          @brainchild Yes, it's a limitation, but not very important in practice. The situation you describe doesn't happen very often. A lot of windowing frameworks work like that, not just Qt, and OS manufacturers don't have any real incentive to break most applications look with new releases. They rather go out of their way not to do that, even when they change the look and feel. Windows APIs and behavior for example haven't changed since Windows XP (over 20 years). The look of the controls changed, some colors maybe, but not the fundamental mechanic. If it happens Qt can just update its platform plugin. The current one didn't need updating for a long time (it's still called WindowsVistaStyle if I'm not mistaken).

                          If you don't like that limitation anyway, you can provide your own platform plugin that will instantiate a bunch of system objects and get rid of that limitation that way. It's a plugin, so it's flexible. Can be updated independently or entirely replaced.

                          B Offline
                          B Offline
                          brainchild
                          wrote on last edited by brainchild
                          #25

                          @Chris-Kawa

                          I am wondering whether the more serious limitation relates to lack of optimization for repainted regions, as a stateful resource would be able to compute the bounds of a physical region having become invalid, based on changes in conceptual state, and its own understanding of how such changes relate to its own paint process.

                          Chris KawaC 1 Reply Last reply
                          0
                          • B brainchild

                            @Chris-Kawa

                            I am wondering whether the more serious limitation relates to lack of optimization for repainted regions, as a stateful resource would be able to compute the bounds of a physical region having become invalid, based on changes in conceptual state, and its own understanding of how such changes relate to its own paint process.

                            Chris KawaC Offline
                            Chris KawaC Offline
                            Chris Kawa
                            Lifetime Qt Champion
                            wrote on last edited by Chris Kawa
                            #26

                            @brainchild I think you overestimate that optimization potential.

                            Simple controls do simple things e.g. a panel will usually just fill it with a color or a gradient. If control has text, like buttons or menu item, it's ballpark the same work to calculate proper text positioning, kerning etc. as simply drawing the whole thing clipped to the region.

                            If you think about it the set of basic UI controls is not that large and they are all pretty basic. More complicated ones like lists, tables etc. are just composition of the basic ones. If you have a very complicated control, like a chart or 3D scene, there's no native controls for that anyway, so all painting is custom one way or another. If you have highly animated UI toolkit it probably draws using an accelerated API like OpenGL or Vulkan, and the cost of figuring out on the CPU sub-changes needed is often a pessimization, as the GPU can draw them faster than the CPU can feed it anyway, so it's actually more performant to just draw it all.

                            I don't think many toolkits do the sub-control optimizations that you think of.

                            B 1 Reply Last reply
                            0
                            • Chris KawaC Chris Kawa

                              @brainchild I think you overestimate that optimization potential.

                              Simple controls do simple things e.g. a panel will usually just fill it with a color or a gradient. If control has text, like buttons or menu item, it's ballpark the same work to calculate proper text positioning, kerning etc. as simply drawing the whole thing clipped to the region.

                              If you think about it the set of basic UI controls is not that large and they are all pretty basic. More complicated ones like lists, tables etc. are just composition of the basic ones. If you have a very complicated control, like a chart or 3D scene, there's no native controls for that anyway, so all painting is custom one way or another. If you have highly animated UI toolkit it probably draws using an accelerated API like OpenGL or Vulkan, and the cost of figuring out on the CPU sub-changes needed is often a pessimization, as the GPU can draw them faster than the CPU can feed it anyway, so it's actually more performant to just draw it all.

                              I don't think many toolkits do the sub-control optimizations that you think of.

                              B Offline
                              B Offline
                              brainchild
                              wrote on last edited by brainchild
                              #27

                              @Chris-Kawa said in Why not use native widgets?:

                              I don't think many toolkits do the sub-control optimizations that you think of.

                              The design that has been familiar to me is that container widgets manage the events of their children, such that it would be important for a container to propagate up the chain the specific bounds of some region that has become invalid, as would correspond to some non-container descendant, to avoid repainting the entire container including descendants. It seems that Qt uses a different model of event propagation, with a widget hierarchy being applied more narrowly to resolve concerns such as position and z-order of paint composition, or recipient of mouse and key events.

                              1 Reply Last reply
                              0
                              • Christian EhrlicherC Offline
                                Christian EhrlicherC Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #28

                                Qt does exactly the same - how should it work otherwise?
                                The code of Qt is open-source - take a look at the event handling or make a breakpoint in your paintEvent() to see where it comes from and you will see the event propagation exactly like it's done in other frameworks.
                                Also Qt is using native drawing methods to draw it's widgets - see the windows style plugin on how it works.

                                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
                                • S Offline
                                  S Offline
                                  SimonSchroeder
                                  wrote on last edited by
                                  #29

                                  @brainchild It seems like you think the native window calls are more performant that Qt's. As has been explained excessively, Qt provides the faster approach by not creating individual OS objects. So, Qt is faster than the native API. You can use a more modern API for Windows for comparable native performance (I don't know any of those). However, these are usually short lived and you need to rewrite your application every couple of years. Qt brings a lot more stability which is a good thing for commercial applications. And as told repeatedly: Qt uses the OS's functionality to draw buttons, labels, combo boxes, etc. An update to the looks by the OS will then also update Qt's look. Rarely does Qt need to change to conform to a new look.

                                  Concerning event handling: Qt translates events one-to-one from the native events to Qt events. No information is lost. There is nothing (nothing I know of) that the native API can do that Qt can't do. I think there are a few special things on macOS. However, there is always the possibility to also receive the native events if you want to. And the optimization of draw calls you have been talking about is also done by Qt. Qt will only request a redraw for the widgets within the QRect, just as the OS would do by itself. And then finally only the part of the native window will be changed with the image from the back buffer. The only "performance penalty" is the use of a back buffer instead directly drawing onto the window. This, however, is necessary for a good user experience anyway. So, the best implementation cannot get any faster than this.

                                  Finally, the reason for using Qt is not to write a Windows program. If you want to do that, just use the native API. The reason for using Qt is writing portable code. And it is still the best tool for writing portable desktop applications. I even think it has the superior API compared to Windows. Concerning the looks of your application: We spend a great deal to have more modern look for our professional application. This means using stylesheets. Using native APIs we would not be able to do that. We specifically switched to Qt to update to a more modern look. Also, we tried to have a similar look on all platforms. For us it is a hindrance that Qt uses the native APIs for drawing controls. I would prefer to not use stylesheets but change colors solely based on the palette. This does not work because Qt uses the native APIs. I would use the Fusion style, but that is honestly too playful for a professional application. Furthermore, some stylesheet changes will break a lot. For example, if you change any part of the look of a QPushButton, layouts will compute a different width for the button. Suddenly, your 'Ok' and 'Cancel' buttons at the bottom of the dialog will have different widths instead of being the same width as expected. So, I vote for Qt to drop the native drawing calls and fake the whole look so I can use palettes instead of stylesheets and not break any layouting while changing the looks.

                                  B 1 Reply Last reply
                                  1
                                  • S SimonSchroeder

                                    @brainchild It seems like you think the native window calls are more performant that Qt's. As has been explained excessively, Qt provides the faster approach by not creating individual OS objects. So, Qt is faster than the native API. You can use a more modern API for Windows for comparable native performance (I don't know any of those). However, these are usually short lived and you need to rewrite your application every couple of years. Qt brings a lot more stability which is a good thing for commercial applications. And as told repeatedly: Qt uses the OS's functionality to draw buttons, labels, combo boxes, etc. An update to the looks by the OS will then also update Qt's look. Rarely does Qt need to change to conform to a new look.

                                    Concerning event handling: Qt translates events one-to-one from the native events to Qt events. No information is lost. There is nothing (nothing I know of) that the native API can do that Qt can't do. I think there are a few special things on macOS. However, there is always the possibility to also receive the native events if you want to. And the optimization of draw calls you have been talking about is also done by Qt. Qt will only request a redraw for the widgets within the QRect, just as the OS would do by itself. And then finally only the part of the native window will be changed with the image from the back buffer. The only "performance penalty" is the use of a back buffer instead directly drawing onto the window. This, however, is necessary for a good user experience anyway. So, the best implementation cannot get any faster than this.

                                    Finally, the reason for using Qt is not to write a Windows program. If you want to do that, just use the native API. The reason for using Qt is writing portable code. And it is still the best tool for writing portable desktop applications. I even think it has the superior API compared to Windows. Concerning the looks of your application: We spend a great deal to have more modern look for our professional application. This means using stylesheets. Using native APIs we would not be able to do that. We specifically switched to Qt to update to a more modern look. Also, we tried to have a similar look on all platforms. For us it is a hindrance that Qt uses the native APIs for drawing controls. I would prefer to not use stylesheets but change colors solely based on the palette. This does not work because Qt uses the native APIs. I would use the Fusion style, but that is honestly too playful for a professional application. Furthermore, some stylesheet changes will break a lot. For example, if you change any part of the look of a QPushButton, layouts will compute a different width for the button. Suddenly, your 'Ok' and 'Cancel' buttons at the bottom of the dialog will have different widths instead of being the same width as expected. So, I vote for Qt to drop the native drawing calls and fake the whole look so I can use palettes instead of stylesheets and not break any layouting while changing the looks.

                                    B Offline
                                    B Offline
                                    brainchild
                                    wrote on last edited by brainchild
                                    #30

                                    @SimonSchroeder

                                    Yes, I have begun to understand better than before. I think the explanation that feels clear to me is that Qt uses native calls to draw the primitive elements with a native appearance, but provides through its own libraries many of the higher-level fundamentals, such as layout and positioning, invalidation of window regions, translation between primitive and high-level events, and so on. Thus, it employs a hybrid model, abstracting most features that port well into its own libraries, but reserving native calls for the lowest-level operations, including painting primitive widgets.

                                    The topic is one that has seemed to be a source of much confusion, not just for me. It might be helpful if the Qt team would include some explanation in the main documentation, or perhaps a post in some blog that is discoverable through a web search.

                                    Christian EhrlicherC 1 Reply Last reply
                                    0
                                    • B brainchild

                                      @SimonSchroeder

                                      Yes, I have begun to understand better than before. I think the explanation that feels clear to me is that Qt uses native calls to draw the primitive elements with a native appearance, but provides through its own libraries many of the higher-level fundamentals, such as layout and positioning, invalidation of window regions, translation between primitive and high-level events, and so on. Thus, it employs a hybrid model, abstracting most features that port well into its own libraries, but reserving native calls for the lowest-level operations, including painting primitive widgets.

                                      The topic is one that has seemed to be a source of much confusion, not just for me. It might be helpful if the Qt team would include some explanation in the main documentation, or perhaps a post in some blog that is discoverable through a web search.

                                      Christian EhrlicherC Offline
                                      Christian EhrlicherC Offline
                                      Christian Ehrlicher
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #31

                                      @brainchild said in Why not use native widgets?:

                                      It might be helpful if the Qt team would include some explanation in the main documentation, or perhaps a post in some blog that is discoverable through a web search.

                                      Why? What exactly do you need? That Qt does it's own painting? Is documented. That Qt abstracts the OS? That's the main purpose for this library.

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

                                      B 1 Reply Last reply
                                      1
                                      • Christian EhrlicherC Christian Ehrlicher

                                        @brainchild said in Why not use native widgets?:

                                        It might be helpful if the Qt team would include some explanation in the main documentation, or perhaps a post in some blog that is discoverable through a web search.

                                        Why? What exactly do you need? That Qt does it's own painting? Is documented. That Qt abstracts the OS? That's the main purpose for this library.

                                        B Offline
                                        B Offline
                                        brainchild
                                        wrote on last edited by
                                        #32

                                        @Christian-Ehrlicher said in Why not use native widgets?:

                                        @brainchild said in Why not use native widgets?:

                                        Why? What exactly do you need? That Qt does it's own painting? Is documented. That Qt abstracts the OS? That's the main purpose for this library.

                                        Perhaps everyone already understands except for me, but it's not my impression reading comments and questions.

                                        1 Reply Last reply
                                        0
                                        • Christian EhrlicherC Offline
                                          Christian EhrlicherC Offline
                                          Christian Ehrlicher
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #33

                                          Read e.g. https://doc.qt.io/qt-6/topics-graphics.html

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

                                          B 1 Reply Last reply
                                          0

                                          • Login

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