PDA

View Full Version : Promoting Widget, plotting



Blitzor DDD
25th July 2016, 14:49
Hello.

I have task to plot a few graphics on different widgets. Since I use QCustomPlot I always need to promote this in Qt Designer Form. It is easy to do when you have just one widget where you will plot something, but what if I need a few different plots simultaneously?

Does the way exist to promote widget from code (not using Qt Designer) or I should use different class (not QCustomPlots).. ?

Thanks in advance!

anda_skoa
25th July 2016, 15:29
You can just add the QCustomPlots in code.
The promote feature is only needed if you want to insert the widget in designer.

Alternatively you can create a designer plugin to be able to have the widget in the toolbox: http://doc.qt.io/qt-5/designer-creating-custom-widgets.html

Cheers,
_

Blitzor DDD
25th July 2016, 16:19
You can just add the QCustomPlots in code.

But I don't need an object. I want just to plot and I do it using QCustomPlots on widget. I do not understand how to connect the new window with QCustomPlot without using Qt Designer Form in order to be able to plot on the new Window.


#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPushButton *ok = new QPushButton("Create new!",this) ;


connect(ok,SIGNAL(clicked(bool)),SLOT(Born()));

}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::Born()
{
QMainWindow *NewWindow=new QMainWindow;

//how to plot here using QCustomPlot?

// NewWindow->setLayout();
NewWindow->show();
}

anda_skoa
25th July 2016, 17:21
But I don't need an object.

How do you expect to use a class like QCustomPlot without creating an object of that class?



I want just to plot and I do it using QCustomPlots on widget

So you are not using QCustomPlot widget?
Then what did you use promoting for?



I do not understand how to connect the new window with QCustomPlot without using Qt Designer Form in order to be able to plot on the new Window.

If the window you are plotting on is not a QCustomPlot widget, what exactly is it?
Your own QWidget subclass?





void MainWindow::Born()
{
QMainWindow *NewWindow=new QMainWindow;

//how to plot here using QCustomPlot?

// NewWindow->setLayout();
NewWindow->show();
}

Well, if you would use QCustomPlot as a widget and not draw on whatever you are using right now, you could simply create an instance of QCustomPlot and set it as NewWindow's central widget.

But that should also work with whatever widget you are using right now.

Cheers,
_

Blitzor DDD
25th July 2016, 17:24
http://www.qcustomplot.com/index.php/tutorials/settingup - I just promote widget to QCustomPlot and use it through ui->widget->name_of_function()


Well, if you would use QCustomPlot as a widget and not draw on whatever you are using right now, you could simply create an instance of QCustomPlot and set it as NewWindow's central widget.

Could you provide an example please?

d_stranz
25th July 2016, 18:12
Could you provide an example please?

OK, if you did in fact follow the instructions at the link you posted, then what you did resulted in a form with an instance of a QCustomPlot object that is named "widget" (if the code you posted is the same as what you did).

So "ui->widget " is a pointer to an instance of QCustomPlot, and it lives in the form that you are using as the central widget of your MainWindow. If you want to use it, then follow this tutorial (http://qcustomplot.com/index.php/tutorials/basicplotting), except that every place it uses the variable named "customplot", you use "ui->widget".

It would probably help you if you chose better names for your QWidget instances than "widget", like in this case maybe "customplot".

anda_skoa
25th July 2016, 18:31
Could you provide an example please?
Example for calling the new operator on a class or for calling a method on an object?

Hmm, you already called the new operator on the QMainWindow class so I guess you need an example on how to call a method.



NewWindow->setCentralWidget(pointerToAWidgetInstance);


Cheers,
_