PDA

View Full Version : Overwriting custom widget stylesheet from mainWindow



pan
11th November 2010, 12:48
I've created a custom widget plugin and set a stylesheet to it.
When I drag it into the designer, then change the mainWindow stylesheet, it doesn't change my widget's style. Is there a way I can force it to do this?

Basically, I want the custom widget (myButton) to have a style while I'm adding it to the designer. I then want this to change from a single main window stylesheet; like from a skinning stylesheet file.

Any suggestions?

high_flyer
11th November 2010, 13:17
from the top of my head:
You could override the constructor (or maybe showEvent()) of your custom widget, to see if it has a parent, and if it does, it should look if the parent uses a style sheet, and then call setStyleSheet() with the parents styleSheet().

pan
11th November 2010, 13:37
Thanks high_flyer.
I had just tried writing a check in the constructor of my widget - on this "window()->styleSheet()" - to see if there was a styleSheet on the top window.
It seems to be close to what I want.
I'll check what I can do in showEvent() perhaps that will be the better option.

high_flyer
11th November 2010, 13:57
I'll check what I can do in showEvent() perhaps that will be the better option.
Now that I think of it, it is the better option (showEvent()), since when you drag a widget from the tool panel in designer, your custom widget is already created, but has no parent.
What you can do in addition to the showEvent() is also overload setParent() to make sure that if parents change the style sheet of the new parent is loaded.

pan
11th November 2010, 14:59
Thanks again.
It works perfectly when I run the app, just need to fix it in the designer... I'll try overloading setParent() now.

pan
12th November 2010, 08:19
I wanted to read the styleSheet from the top level (QMainWindow). It works fine when I run the app, but during the designer phase my widget can't seem to find the top window through the method: window()

Is there a way to get around this whilst in the designer?

high_flyer
12th November 2010, 08:41
I don't think so.
The forms in designer are not in an application.
The designer only helps you save some typing when you design your forms, and makes it easier to use layouts etc.
If you want to have things adjust like that in designer you will have to change designer it self!

pan
12th November 2010, 09:15
Ok. Good to know the limitation. Working at runtime is a good enough solution.

I had been looking at this: QDesignerFormWindowInterface

But still wasn't able to access the main window.
Thanks for replying so quickly.

high_flyer
12th November 2010, 09:31
I had been looking at this: QDesignerFormWindowInterface

But still wasn't able to access the main window.

Heh, you are one step ahead of me, the trolls have added so much in last few Qt releases, that I have trouble to keep up, speically with such not very often used classes.
From a brief look in to QDesignerFormWindowInterface, I think that just might be what you are looking for.
Have a look at QDesignerFormEditorInterface::formWindowManager (), and then in QDesignerFormWindowManagerInterface.
I am almost certain that this will allow you to get the form styleSheet on which your custom widget is dropped.

pan
12th November 2010, 14:50
I finally got it working:


form = QDesignerFormWindowInterface::findFormWindow(widge t);
form->mainContainer()->styleSheet();

This works for the designer.