Qt6 QProxyStyle cause app crash
-
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?! :-( -
@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. -
Hi,
You might want to consider opening a new report with your issue providing your example script.
-
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.
-
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().
-
@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
-
@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.
-
When you create a new style you also have to apply your own palette if you want to same as the app style.
-
@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. -
@Dariusz said in Qt6 QProxyStyle cause app crash:
But how can I properly replicate it ?
Apply the same things to the newly created style.
-
@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
-
Then don't use this approach and don't delete the proxy style.
-
@Christian-Ehrlicher So I will have memory leak... I have to delete treeview when user changes properties...
-
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?
-
@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" :- (
-
Sorry but I still don't see why you need to delete and re-create the proxy style. But do what you like.