Is is possible to edit an individual Widget in the QtDesginer?

左心房为你撑大大i 提交于 2019-12-25 01:36:46

问题


I got a external library, which includes a derived class from QGLWidget, very similar to that one here. In that library I have a class:

class PictureGLWidget : public QGLWidget { //.. }

This extends Qt's native QGLWidget and personalizes it. But it was not written by me, I just got it, via a *.dll. So then, I bind that Widget manually in my code to a layout like:

QGridLayout* layout = new QGridLayout;
layout->addWidget(myPictureGLWidget, 0, 1);
ui->verticalLayout_5->addLayout(layout);

since I designed my MainWindowWidget with the integrated QtDesigner, which is by the way very comfortable, I would like to handle my myPictureGLWidget also in the QtDesigner, since I am currently redesigning the MainWindow.

Is there a way doing that? Thnx in advance!


回答1:


Qt Designer supports any foreign widget class without needing to provide plugins for that. You only have to accept that the widget's properties and appearance won't be available within Designer.

  1. Insert a dummy QWidget into the layout.

  2. Right click on the widget, select "Promote to...".

  3. Add PictureGLWidget as a new class promoted from QWidget. Specify appropriate header files etc.

  4. Promote your widget to PictureGLWidget.

When this is done, the code generated by uic will instantiate a PictureGLWidget where you need it, instead of a dummy QWidget.

If you want to use the PictureGLWidget in the designer instead of a dummy widget, you can write a designer plugin that wraps the widget and exposes it in the widget pallette, provides property support, etc.




回答2:


I might have misunderstood your question but don't you just add a QGLWidget to your design in Designer. Right click the widget and select Promote to... ?



来源:https://stackoverflow.com/questions/31558297/is-is-possible-to-edit-an-individual-widget-in-the-qtdesginer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!