Unsolved Custom Widget Plug-in for Qt designer.
-
Hi,
I have develop custom widget (with the help of Qt C++) for qt designer. For developing custom widget, I have used paintEvent() function to draw my widget. Under paintEvent() function, I have used QPainter object to draw appropriate widget. My question is here, how many ways to integrate custom widget plugin into qt designer. I have used one way to create custom widget plugin. I refereed below given link to create custom widget-
http://www.ics.com/blog/integrating-custom-widget-qt-designer
Is there another way to create custom widget plugins for qt- designer? Please suggest me.
Thanks.
-
Have you referred this ?
and this example http://doc.qt.io/qt-5/qtdesigner-customwidgetplugin-example.html
or this https://techbase.kde.org/Development/Tutorials/Writing_Qt_Designer_Plugins -
Hi
If you custom widget do not need new properties to be edited or full integration, there
is also the "Promote" feature that let you use a custom widget in Designer without all the plugin code. -
Thanks a lot Ratzz
But I have used your way. I have prepared all my custom widgets according to your suggestions.
May you clarify my query please :
Is each custom (or) standard widget prepared with the help of QPainter object? -
-
@amitgolhani
Hi
Nope that is the way.
Only note is that if you have mutiple custom widgets then
http://doc.qt.io/qt-5/qdesignercustomwidgetcollectioninterface.html
might be handy. -
Thanx mrjj. I have tried this.
Please give me one more solution. I draw my custom widget with the help of Qt C++. And I am using QPainter object to draw my custom widget (Like painter.drawEllipse() ). Can I draw my custom widget another way?
Actually I am not applying stylesheet into QPainter object. Style sheets for custom widget like background color, border-color, gradient etc.
Thanx
-
@amitgolhani
Hi
All widgets draw themself with painter.
Instead of using painter calls (like drawEllipse) you can use an image.
Otherwise using painter is how widgets draw themself.
Often using stylesvoid MyWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); ... QStyleOptionFocusRect option(1); option.init(this); option.backgroundColor = palette().color(QPalette::Window); style().drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this); }
-
Actually I am using painter.drawEllipse() call to draw an ellipse. How do I apply style only inside ellipse area?
You can see in the below image-Thanx
-
@amitgolhani
Hi, please use external site for image.
Pictures are broken here and we cant see.- How do I apply style only inside ellipse area
What style ? Its not clear what you mean.
- How do I apply style only inside ellipse area
-
Hi Mrjj,
Actually I prepared an ellipse custom widget. I integrated it into qt designer. I want to apply styleSheet from property editor of qt designer.
I want to apply all styleSheet only inside ellipse widget not for whole selected widget in the qt designer.
How will I achieve the same?NOTE:
Style-sheet like background-color, border-color, gradient ,background picture etc. etc. -
Hi
The things you set in stylesheet is used via QStyle style()->drawControlLike
http://stackoverflow.com/questions/11901037/how-to-render-a-red-push-button-using-qstyle-drawcontrol
class Widget : public QWidget { // To allow the automatic deletion without parenting it QScopedPointer<QPushButton> button; public: Widget() : button(new QPushButton) { button->setStyleSheet("background-color: red"); } virtual void paintEvent(QPaintEvent* event) { QStyleOptionButton opt; opt.state = QStyle::State_Active | QStyle::State_Enabled; opt.rect = QRect(50, 25, 100, 50); QPainter painter(this); button->style()->drawControl(QStyle::CE_PushButton, &opt, &painter, button.data()); } };
Sadly there is no direct Style for an ellipse so unless you can you can find a Control look to res-use ( a QStyleOptionXXX),
then you have to draw it all by hand.