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. Qt6 QProxyStyle cause app crash

Qt6 QProxyStyle cause app crash

Scheduled Pinned Locked Moved Unsolved General and Desktop
qproxystyleqstyleqapplication
17 Posts 4 Posters 2.2k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 15 Feb 2021, 23:44 last edited by Dariusz
    #1

    Hey

    This code will crash >

    import sys
    
    from PySide6.QtWidgets import QApplication, QProxyStyle, QWidget
    app = QApplication()
    
    class MyProxyStyle(QProxyStyle):
        def __init__(self):
            QProxyStyle.__init__(self)
            self.setBaseStyle(QApplication.style())
    s =MyProxyStyle()
    s.deleteLater()
    w =QWidget()
    w.show()
    sys.exit(app.exec_())
    

    Can any1 think of any workaround in meantime?
    Or am I doing something wrong here? Maybe its not a bug but a user error?

    Possibly related to > https://bugreports.qt.io/browse/PYSIDE-922
    Shish... so I cant use proxy style... how am I gonna style my tree view?! :-(

    E 1 Reply Last reply 16 Feb 2021, 00:06
    0
    • D Dariusz
      15 Feb 2021, 23:44

      Hey

      This code will crash >

      import sys
      
      from PySide6.QtWidgets import QApplication, QProxyStyle, QWidget
      app = QApplication()
      
      class MyProxyStyle(QProxyStyle):
          def __init__(self):
              QProxyStyle.__init__(self)
              self.setBaseStyle(QApplication.style())
      s =MyProxyStyle()
      s.deleteLater()
      w =QWidget()
      w.show()
      sys.exit(app.exec_())
      

      Can any1 think of any workaround in meantime?
      Or am I doing something wrong here? Maybe its not a bug but a user error?

      Possibly related to > https://bugreports.qt.io/browse/PYSIDE-922
      Shish... so I cant use proxy style... how am I gonna style my tree view?! :-(

      E Offline
      E Offline
      eyllanesc
      wrote on 16 Feb 2021, 00:06 last edited by
      #2

      @Dariusz why you call to s.deleteLater()?

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      D 1 Reply Last reply 16 Feb 2021, 00:12
      0
      • E eyllanesc
        16 Feb 2021, 00:06

        @Dariusz why you call to s.deleteLater()?

        D Offline
        D Offline
        Dariusz
        wrote on 16 Feb 2021, 00:12 last edited by
        #3

        @eyllanesc To delete proxy stylesheet.
        I have an app that deletes tree views. Tree view that uses this style will delete ProxyStyle too. Which then deletes QStyle which means that QApplication Style dies.
        QProxyStyle should not take ownership of style if its used by QApplication.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 16 Feb 2021, 20:52 last edited by
          #4

          Hi,

          You might want to consider opening a new report with your issue providing your example script.

          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
          0
          • C Online
            C Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 16 Feb 2021, 21:42 last edited by
            #5

            When you delete the style you also delete the base style as explained in the documentation (not Qt6 related):

            Sets the base style that should be proxied.
            Ownership of style is transferred to QProxyStyle.

            Therefore create a new base style instead using the QApplication default one.

            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
            1
            • D Offline
              D Offline
              Dariusz
              wrote on 22 Feb 2021, 18:31 last edited by Dariusz
              #6

              Hey

              Ok still fighting with this...

              I can set a QStyle() on QProxyStyle, but how can I then set QPalette on it & styleSheet?

              I tried with >

                      s = QStyleFactory.create("fusion")
                      s.polish(m.getPalette()) 
                      s.setStyleShet(""" data""") ?????
                      self.setBaseStyle(s)
              

              Any ideas?

              TIA

              The problem I'm having is that I can't get it to look the same as when I take QApplication::style().

              1 Reply Last reply
              0
              • C Online
                C Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 22 Feb 2021, 18:49 last edited by
                #7

                @Dariusz said in Qt6 QProxyStyle cause app crash:

                The problem I'm having is that I can't get it to look the same as when I take QApplication::style().

                Maybe your app isn't using the fusion style? Use the correct style which you app is using. The name of the style can only be retrieved via QApplication::style()->objectName() till Qt6.0, for 6.1 you can use a better function - QStyle::name() - see https://codereview.qt-project.org/c/qt/qtbase/+/328116

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

                D 1 Reply Last reply 22 Feb 2021, 19:32
                0
                • C Christian Ehrlicher
                  22 Feb 2021, 18:49

                  @Dariusz said in Qt6 QProxyStyle cause app crash:

                  The problem I'm having is that I can't get it to look the same as when I take QApplication::style().

                  Maybe your app isn't using the fusion style? Use the correct style which you app is using. The name of the style can only be retrieved via QApplication::style()->objectName() till Qt6.0, for 6.1 you can use a better function - QStyle::name() - see https://codereview.qt-project.org/c/qt/qtbase/+/328116

                  D Offline
                  D Offline
                  Dariusz
                  wrote on 22 Feb 2021, 19:32 last edited by
                  #8

                  @Christian-Ehrlicher Yeah I do

                  In general I do something like this

                  app.setStyle(QStyleFactory.create("fusion"))
                  QPalette pa
                  /*pa set bunch of pa options */
                  app.setPalette(pa)
                  app.setStyleSheet(""" style stuff""")
                  

                  But the QProxyStyle sheet does not properly clone it. So I'm trying to manually make a new one, assign it and well not cause any mem error... So far I'm failing left and right.

                  1 Reply Last reply
                  0
                  • C Online
                    C Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 22 Feb 2021, 20:23 last edited by
                    #9

                    When you create a new style you also have to apply your own palette if you want to same as the app style.

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

                    D 1 Reply Last reply 23 Feb 2021, 10:55
                    0
                    • C Christian Ehrlicher
                      22 Feb 2021, 20:23

                      When you create a new style you also have to apply your own palette if you want to same as the app style.

                      D Offline
                      D Offline
                      Dariusz
                      wrote on 23 Feb 2021, 10:55 last edited by
                      #10

                      @Christian-Ehrlicher said in Qt6 QProxyStyle cause app crash:

                      When you create a new style you also have to apply your own palette if you want to same as the app style.

                      Yes but I can't get it to work.
                      I apply QStyle, Palette and StyleSheet to my QApp. But how can I properly replicate it ? I tried making a widget and then taking it from widget. But that did not work either. And QProxyStyle wrecks havoc when it gets a style each time.

                      1 Reply Last reply
                      0
                      • C Online
                        C Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 23 Feb 2021, 15:03 last edited by
                        #11

                        @Dariusz said in Qt6 QProxyStyle cause app crash:

                        But how can I properly replicate it ?

                        Apply the same things to the newly created style.

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

                        D 1 Reply Last reply 23 Feb 2021, 18:59
                        0
                        • C Christian Ehrlicher
                          23 Feb 2021, 15:03

                          @Dariusz said in Qt6 QProxyStyle cause app crash:

                          But how can I properly replicate it ?

                          Apply the same things to the newly created style.

                          D Offline
                          D Offline
                          Dariusz
                          wrote on 23 Feb 2021, 18:59 last edited by
                          #12

                          @Christian-Ehrlicher said in Qt6 QProxyStyle cause app crash:

                          @Dariusz said in Qt6 QProxyStyle cause app crash:

                          But how can I properly replicate it ?

                          Apply the same things to the newly created style.

                          I can't set styleSheet() on style... So I cant style the Style... o.o

                          1 Reply Last reply
                          0
                          • C Online
                            C Online
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on 23 Feb 2021, 19:10 last edited by Christian Ehrlicher
                            #13

                            Then don't use this approach and don't delete the proxy style.

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

                            D 1 Reply Last reply 23 Feb 2021, 19:18
                            0
                            • C Christian Ehrlicher
                              23 Feb 2021, 19:10

                              Then don't use this approach and don't delete the proxy style.

                              D Offline
                              D Offline
                              Dariusz
                              wrote on 23 Feb 2021, 19:18 last edited by
                              #14

                              @Christian-Ehrlicher So I will have memory leak... I have to delete treeview when user changes properties...

                              1 Reply Last reply
                              0
                              • C Online
                                C Online
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on 24 Feb 2021, 15:00 last edited by
                                #15

                                But why do you have to re-create the style then? Apart from that - why do you need to re-create a treeview widget at all?

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

                                D 1 Reply Last reply 24 Feb 2021, 18:21
                                0
                                • C Christian Ehrlicher
                                  24 Feb 2021, 15:00

                                  But why do you have to re-create the style then? Apart from that - why do you need to re-create a treeview widget at all?

                                  D Offline
                                  D Offline
                                  Dariusz
                                  wrote on 24 Feb 2021, 18:21 last edited by
                                  #16

                                  @Christian-Ehrlicher The app creates content depending on user selection. Different content require different views as well as I can have multiple views for one content... so widgets gets made/deleted on a "normal basis". So deleting widget/treeView is a normal thing. It seems that this issue is even bigger on older OS as win7 just refuses to draw app after these "workarounds" :- (

                                  1 Reply Last reply
                                  0
                                  • C Online
                                    C Online
                                    Christian Ehrlicher
                                    Lifetime Qt Champion
                                    wrote on 24 Feb 2021, 18:34 last edited by
                                    #17

                                    Sorry but I still don't see why you need to delete and re-create the proxy style. But do what you like.

                                    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

                                    9/17

                                    22 Feb 2021, 20:23

                                    • Login

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