Hi @all,
i have made a subclass of QPushButton.
This I had successfully assigned using "Promote To".
Is there a way to set some Variables for the Constructor anywhere?
Best Regards
NoRulez
Hi @all,
i have made a subclass of QPushButton.
This I had successfully assigned using "Promote To".
Is there a way to set some Variables for the Constructor anywhere?
Best Regards
NoRulez
No, you have to rely on the default constructor if you want the widget created from within Designer generated code.
...and if you want set your custom properties in the designer, you have to write a plugin for the designer, which is not so hard.
Could you provide me a sample or something similar to use custom properties within the designer? A pluginexample is in the documentation, but what about custom properties? If I'm right, than you mean Q_PROPERTY?
Regards
NoRulez
It's also in that documentation! E.g. the "Container Extension" example. Look also at QDesignerPropertySheetExtension. But that is not necessary at all, since you also add dynamic properties directly in the designer: Use the plus near to the filter in the property editor.
OK, I've found it. It seems that this function is new in Qt 4.5.
So, now I added 2 pixmaps as follows: pressedPixmap = :/images/pressedButton.png" and normalPixmap = ":/images/normalButton.png".
Now i want to call my own constructor:
MyButton(QPixmap pressed, QPixmap normal);
This is the point where i don't know how to call it.
Regards
NoRulez
Note, that you have to have proper Q_PROPERTY to do so!
That's not possible. And also not necessary. If you callMyButton(QPixmap pressed, QPixmap normal);
This is the point where i don't know how to call it.orQt Code:
To copy to clipboard, switch view to plain text modedoesn't matter.Qt Code:
MyButton mb;To copy to clipboard, switch view to plain text mode
It does a matter, because after the constructor the sizeHint() function is called.
The sizeHint() function should return the size of the image, otherwise the function returns 0x0 (width x height). At this point the sizeHint() returns 0x0, because the image is defined after the sizeHint() call.
So if i call a function then the following are done:
Qt Code:
MyButton(); sizeHint()To copy to clipboard, switch view to plain text mode
I need to set the image before the sizeHint() function is called.
So I thought the best way is the constructor.
Regards
NoRulez
Last edited by NoRulez; 22nd June 2009 at 16:54.
Don't understand. For what do you mean the size hint is important? for the correct arrangement in a layout? it will be adjusted even if you set the images after the c-tor is called. And by the way, the designer is creating the instructions exactly that way:
So no other function is called between and if you don't call sizeHint() in your own c-tor, there is no difference.Qt Code:
MyButton mb;To copy to clipboard, switch view to plain text mode
The BaseClass (QPushButton) calls the sizeHint() function. If you use debug messages in the overloaded functions you will see that the sizeHint() is called after the constructor. After the sizeHint() the other functions are called.
So when the size of my Pixmap is for example 250x130. then my button should also be the same size. To set the size of the button you could also write:
But within this function I haven't the pixmap when I can't set it within the constructorQt Code:
//return normalButton.size(); }To copy to clipboard, switch view to plain text mode
I hope you could understand what i mean.
Regards
NoRulez
There is no "after the constructor". Besides, the sizeHint() can change, just call QWidget::updateGeometry() from within the methods used to set up the images. sizeHint() will be called again.
Bookmarks