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. QMessageBox subclass has different appearance from base class in macOS (even when calling base constructor)

QMessageBox subclass has different appearance from base class in macOS (even when calling base constructor)

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 5 Posters 705 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.
  • G Offline
    G Offline
    GrecKo
    Qt Champions 2018
    wrote on 17 Sept 2024, 08:19 last edited by
    #3

    Also maybe this can be worked-around. What is your goal for subclassing QMessageBox? Can this be achieved in another way?

    My random guess is that only non-subclassed QMessageBox get the native look while subclasses get a generic one allowing them to be customized.

    1 Reply Last reply
    2
    • J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 17 Sept 2024, 08:28 last edited by
      #4

      So I tested this, its the same for pyside6

      @GrecKo that shouldn't be really possible, right? It's a direct subclass of QMessageBox it should use the same styles, call the same functions, as non are overridden.

      Maybe it's a global stylesheet ? IIRC those can have a Class-Tag and could potentially no longer apply to derived classes🤔


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      J 1 Reply Last reply 17 Sept 2024, 08:47
      0
      • J J.Hilk
        17 Sept 2024, 08:28

        So I tested this, its the same for pyside6

        @GrecKo that shouldn't be really possible, right? It's a direct subclass of QMessageBox it should use the same styles, call the same functions, as non are overridden.

        Maybe it's a global stylesheet ? IIRC those can have a Class-Tag and could potentially no longer apply to derived classes🤔

        J Offline
        J Offline
        JonB
        wrote on 17 Sept 2024, 08:47 last edited by JonB
        #5

        @J-Hilk said in QMessageBox subclass has different appearance from base class in macOS (even when calling base constructor):

        @GrecKo that shouldn't be really possible, right? It's a direct subclass of QMessageBox it should use the same styles, call the same functions, as non are overridden.

        Not necessarily. This was my thought too yesterday, but I didn't feel like replying in view of the vitriol. Although it is unusual for code to check whether something is a subclass rather that actually of a certain class exactly it is not impossible. My hunch was that code (maybe Mac only, maybe not) only uses some "native" style when object is QMessageBox but not subclass. Perhaps because it considers that once you subclass all bets are off for using "native" as it does not know what you are going to do. A little bit like when you do style on some widgets they change from "native" style. One would have to check code.

        J 1 Reply Last reply 17 Sept 2024, 08:57
        0
        • J JonB
          17 Sept 2024, 08:47

          @J-Hilk said in QMessageBox subclass has different appearance from base class in macOS (even when calling base constructor):

          @GrecKo that shouldn't be really possible, right? It's a direct subclass of QMessageBox it should use the same styles, call the same functions, as non are overridden.

          Not necessarily. This was my thought too yesterday, but I didn't feel like replying in view of the vitriol. Although it is unusual for code to check whether something is a subclass rather that actually of a certain class exactly it is not impossible. My hunch was that code (maybe Mac only, maybe not) only uses some "native" style when object is QMessageBox but not subclass. Perhaps because it considers that once you subclass all bets are off for using "native" as it does not know what you are going to do. A little bit like when you do style on some widgets they change from "native" style. One would have to check code.

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 17 Sept 2024, 08:57 last edited by
          #6

          @JonB Qt classes don't require/use RTTI so It would have to be some Qt equivalent to typeid

          after a Quick Look into the dokumention, QObject has inherits(), but "A class is considered to inherit itself." So that doesn't work.

          All other methods I can think of would require the method to know about the derived class beforehand 🤷‍♂️


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          J 1 Reply Last reply 17 Sept 2024, 09:26
          1
          • G Offline
            G Offline
            GrecKo
            Qt Champions 2018
            wrote on 17 Sept 2024, 09:25 last edited by
            #7

            metaObject()->className() == "QMessageBox" does the trick.

            J 1 Reply Last reply 17 Sept 2024, 09:27
            3
            • J J.Hilk
              17 Sept 2024, 08:57

              @JonB Qt classes don't require/use RTTI so It would have to be some Qt equivalent to typeid

              after a Quick Look into the dokumention, QObject has inherits(), but "A class is considered to inherit itself." So that doesn't work.

              All other methods I can think of would require the method to know about the derived class beforehand 🤷‍♂️

              J Offline
              J Offline
              JonB
              wrote on 17 Sept 2024, 09:26 last edited by
              #8

              @J-Hilk said in QMessageBox subclass has different appearance from base class in macOS (even when calling base constructor):

              @JonB Qt classes don't require/use RTTI so It would have to be some Qt equivalent to typeid

              Ah. I believe Python can test this, and OP is using Python, but one would not have thought there would be special Python code here.

              Fair enough. It leaves us at a bit of a loss then where OP shows a completely different style for a derived QMessageBox from a base one....

              1 Reply Last reply
              1
              • G GrecKo
                17 Sept 2024, 09:25

                metaObject()->className() == "QMessageBox" does the trick.

                J Offline
                J Offline
                JonB
                wrote on 17 Sept 2024, 09:27 last edited by
                #9

                @GrecKo said in QMessageBox subclass has different appearance from base class in macOS (even when calling base constructor):

                metaObject()->className() == "QMessageBox" does the trick.

                Yes indeed. I don't how likely it is that either all Qt code or perhaps MacOS-specific implementation for calling native QMessageBox would do this?

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on 17 Sept 2024, 09:45 last edited by
                  #10

                  It's done here : https://github.dev/qt/qtbase/blob/308bca94a72f83624e2e2c92449719e06940e77f/src/widgets/dialogs/qmessagebox.cpp#L2800-L2801

                  Commit with its comments can be found here : https://codereview.qt-project.org/c/qt/qtbase/+/472618

                  I guess PyQt6 automatically defines Q_OBJECT for Qt subclasses?

                  J 1 Reply Last reply 17 Sept 2024, 10:11
                  4
                  • G GrecKo
                    17 Sept 2024, 09:45

                    It's done here : https://github.dev/qt/qtbase/blob/308bca94a72f83624e2e2c92449719e06940e77f/src/widgets/dialogs/qmessagebox.cpp#L2800-L2801

                    Commit with its comments can be found here : https://codereview.qt-project.org/c/qt/qtbase/+/472618

                    I guess PyQt6 automatically defines Q_OBJECT for Qt subclasses?

                    J Offline
                    J Offline
                    JonB
                    wrote on 17 Sept 2024, 10:11 last edited by JonB
                    #11

                    @GrecKo
                    Absolutely perfect, thanks for finding this! So it does do what I suspected it might :)

                    P.S.
                    I would assume this is also the case for other dialogs etc. where there is a "native" implementation on offer, e.g. QFileDialog? Once Qt sees it has been subclassed it does not know what you might be doing/adding so it moves over to a Qt-non-native implementation so that it will "work". For the native ones you can use whatever it might allow for its own configuration (e.g. perhaps styling) but you must not subclass. Maybe documentation should mention this?

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      GrecKo
                      Qt Champions 2018
                      wrote on 17 Sept 2024, 11:44 last edited by GrecKo
                      #12

                      Reading the comments in the commit it appears this is not an intended behavior, and it was considered not that big of a deal since not many subclasses would use Q_OBJECT to declare a descendant metaobject. PyQt appears to do so though, that is a bit unfortunate in this case.

                      This warrants a bug report on Qt's JIRA and then it goes back to my initial question: Why subclass QMessageBox?

                      J 1 Reply Last reply 17 Sept 2024, 12:23
                      2
                      • G GrecKo
                        17 Sept 2024, 11:44

                        Reading the comments in the commit it appears this is not an intended behavior, and it was considered not that big of a deal since not many subclasses would use Q_OBJECT to declare a descendant metaobject. PyQt appears to do so though, that is a bit unfortunate in this case.

                        This warrants a bug report on Qt's JIRA and then it goes back to my initial question: Why subclass QMessageBox?

                        J Offline
                        J Offline
                        JonB
                        wrote on 17 Sept 2024, 12:23 last edited by
                        #13

                        @GrecKo said in QMessageBox subclass has different appearance from base class in macOS (even when calling base constructor):

                        since not many subclasses would use Q_OBJECT to declare a descendant metaobject

                        Ohhh! You are saying that only if you use Q_OBJECT in a subclass does metaObject()->className() get changed to the subclass name?! I did not get that from your earlier post and did not understand how Q_OBJECT was relevant. It would not surprise me if PyQt or PySide automatically did Q_OBJECT, don't think that exists for the Python user.

                        I am not volunteering to report this, if you feel like it that's up to you.

                        So if OP could prevent that from PyQt then he would get away with subclassing.

                        I do not know why he feels he wants to subclass. He may have to rethink in light of this discovery.

                        1 Reply Last reply
                        0

                        12/13

                        17 Sept 2024, 11:44

                        • Login

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