Page 1 of 1

Integrating a Qt Widget in a plugin

Posted: Fri Jul 21, 2017 3:42 pm
by CLbs
Hi all,

I'm really new to Qt and CC and I developed a little Qt application with my own class just opening a window with some widget inside, alone it works fine with just the following main :
// Create the Qt app
QApplication app(argc, argv);
// Create my own window
MyWidget window;
window.show();
return app.exec();

something very basic.

And I was wondering how to include that in a CC plugin.
I followed the tutorial and recompiled CC and my new plugin appears in the list when CC is launched but after nothing happened except for the default dummy plugin actions.

I didn't succeed too in calling just a basic Qt widget from the doAction function this way :

QWidget fenetre((QWidget*)m_app->getMainWindow());
fenetre.setFixedSize(300, 150);
fenetre.show();


Is it the right way to do it or there are some changes to do in my class to display directly a Qt window ?? Or it is impossible ??

Sorry for the long post and thanks for your help.

Clement

Re: Integrating a Qt Widget in a plugin

Posted: Sat Jul 22, 2017 4:54 pm
by daniel
You should look at how this is done in other plugins.

In a Qt application, there can only be one 'main window' (QMainWindow). And only one 'Application' (QApplication). And CloudCompare is already instantiating them.

To open a new 'window' over CC's one, you simply have to create a QDialog. Either you make your 'widget' derive from QDialog, or you include your widget (if it derives from QWidget) inside a QDialog.

After that you simply have to call 'mydialog.exec()' to make it visible and blocking, or simply 'mydialog.show()' to make it visible but not blocking.

The simplest example is the 'PCV' plugin (see QPCV_PLUGIN).