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)
Forum Updated to NodeBB v4.3 + New Features

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 874 Views 2 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.
  • J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on 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.

    JonBJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      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🤔

      JonBJ Online
      JonBJ Online
      JonB
      wrote on 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.HilkJ 1 Reply Last reply
      0
      • JonBJ JonB

        @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.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on 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.

        JonBJ 1 Reply Last reply
        1
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #7

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

          JonBJ 1 Reply Last reply
          3
          • J.HilkJ J.Hilk

            @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 🤷‍♂️

            JonBJ Online
            JonBJ Online
            JonB
            wrote on 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
            • GrecKoG GrecKo

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

              JonBJ Online
              JonBJ Online
              JonB
              wrote on 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
              • GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on 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?

                JonBJ 1 Reply Last reply
                4
                • GrecKoG GrecKo

                  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?

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on 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
                  • GrecKoG Offline
                    GrecKoG Offline
                    GrecKo
                    Qt Champions 2018
                    wrote on 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?

                    JonBJ 1 Reply Last reply
                    2
                    • GrecKoG GrecKo

                      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?

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on 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

                      • Login

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