I have a custom widget from modified elastic nodes example. It inherits from QGraphicsView. In the example it is set as a central widget in the main window, so nothing can be added. Here's the code for main from the example:
#include "graphwidget.h"
#include <QApplication>
#include <QTime>
#include "mainwindow.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
GraphWidget *widget = new GraphWidget;
QMainWindow window;
window.setCentralWidget(widget);
window.show();
return app.exec();
}
I want to add the widget to the ui form, so that i can add some buttons and input. How can i do that?
What you are doing now is making an application.
If you want to make a custom widget in Qt , you need to build it as Custom Designer Widget - a plugin (as Dll).
In Qt creator choose OtherProject=>Qt Custom Designer Widget and create a project. You need to build as Release version, not the debug one.
After building, if Qt hasn't already, you need to copy the .dll
file into Qt/plugins/designer
and Qt/Tools/QtCreator/bin/plugins
- you will find .dll's there. You also need to build plugin with tool chain, as Qt creator/designer was i.e. VisualStudio 2013 64bit or Mingw - MUST be the SAME.
It's not easy, but i wish you luck.