PDA

View Full Version : how i can increase the size of my plots and have a good organisation of this widget ?



21did21
27th May 2011, 00:26
Hello world,

i use QtCreator and Qwt, i try to plot in real time 6 curve but i not a master in programmation and it's very difficult for me...
Qwt use widget which have name "plot", it work like all the other widget but i can't increase their size and i don't know why...

can you help me to:
1°) place my curve correctly
2°) with the good size

i do a project to place 6curve and 4button on a windows, the result is nice (http://imageshack.us/photo/my-images/851/myplots.jpg/) but i want to increase the size of my plot and have a good arrangement
==> the plots have to take the total windows (except button emplacement)

How i have to modify this programm to have bigger plots with a good arrangement ?
main.cpp


#include <QApplication>
#include "MyMainWindow.h"
#include <QGridLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyMainWindow fenetre;
fenetre.setWindowFlags(Qt::Window);

QGridLayout *MyGridLayout = new QGridLayout;
MyGridLayout->addWidget(fenetre.get_WindowNumber1(),0,0,3,3);
MyGridLayout->addWidget(fenetre.get_WindowNumber2(),0,3,3,3);
MyGridLayout->addWidget(fenetre.get_WindowNumber3(),0,6,3,3);
MyGridLayout->addWidget(fenetre.get_WindowNumber4(),3,0,3,3);
MyGridLayout->addWidget(fenetre.get_WindowNumber5(),3,3,3,3);
MyGridLayout->addWidget(fenetre.get_WindowNumber6(),3,6,3,3);
MyGridLayout->addWidget(fenetre.get_BUTTONRun(),0,8);
MyGridLayout->addWidget(fenetre.get_BUTTONQuit(),0,9);
MyGridLayout->addWidget(fenetre.get_BUTTONAbout(),1,8);
MyGridLayout->addWidget(fenetre.get_BUTTONContact(),1,9);
fenetre.setLayout(MyGridLayout);
fenetre.show();
return app.exec();
}

MyMainWindow.h

#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H

#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QMessageBox>
#include <qwt_plot.h>

class MyMainWindow : public QWidget
{
Q_OBJECT

public:
MyMainWindow();
~MyMainWindow();
QPushButton* get_BUTTONRun();
QPushButton* get_BUTTONQuit();
QPushButton* get_BUTTONAbout();
QPushButton* get_BUTTONContact();
QWidget* get_WindowNumber1();
QWidget* get_WindowNumber2();
QWidget* get_WindowNumber3();
QWidget* get_WindowNumber4();
QWidget* get_WindowNumber5();
QWidget* get_WindowNumber6();

private:
QPushButton *BUTTONRun;
QPushButton *BUTTONQuit;
QPushButton *BUTTONAbout;
QPushButton *BUTTONContact;
QWidget *WindowNumber1;
QWidget *WindowNumber2;
QWidget *WindowNumber3;
QWidget *WindowNumber4;
QWidget *WindowNumber5;
QWidget *WindowNumber6;
QwtPlot *myPlot1;
QwtPlot *myPlot2;
QwtPlot *myPlot3;
QwtPlot *myPlot4;
QwtPlot *myPlot5;
QwtPlot *myPlot6;
};
#endif // MYMAINWINDOW_H
MyMainWindow.cpp


#include "MyMainWindow.h"

MyMainWindow::MyMainWindow() : QWidget()
{
WindowNumber1= new QWidget(this);
WindowNumber2= new QWidget(this);
WindowNumber3= new QWidget(this);
WindowNumber4= new QWidget(this);
WindowNumber5= new QWidget(this);
WindowNumber6= new QWidget(this);
myPlot1=new QwtPlot(WindowNumber1);
myPlot2=new QwtPlot(WindowNumber2);
myPlot3=new QwtPlot(WindowNumber3);
myPlot4=new QwtPlot(WindowNumber4);
myPlot5=new QwtPlot(WindowNumber5);
myPlot6=new QwtPlot(WindowNumber6);

BUTTONRun = new QPushButton("RUN", this);
BUTTONQuit = new QPushButton("STOP", this);
BUTTONAbout = new QPushButton("About", this);
BUTTONContact = new QPushButton("Contact", this);

QObject::connect(BUTTONQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
QObject::connect(BUTTONAbout, SIGNAL(clicked()), qApp, SLOT(aboutQt()));

}
MyMainWindow::~MyMainWindow()
{

}

QPushButton* MyMainWindow::get_BUTTONRun()
{
return BUTTONRun;
}

QPushButton* MyMainWindow::get_BUTTONQuit()
{
return BUTTONQuit;
}

QPushButton* MyMainWindow::get_BUTTONAbout()
{
return BUTTONAbout;
}

QPushButton* MyMainWindow::get_BUTTONContact()
{
return BUTTONContact;
}

QWidget* MyMainWindow::get_WindowNumber1()
{
return WindowNumber1;
}

QWidget* MyMainWindow::get_WindowNumber2()
{
return WindowNumber2;
}

QWidget* MyMainWindow::get_WindowNumber3()
{
return WindowNumber3;
}

QWidget* MyMainWindow::get_WindowNumber4()
{
return WindowNumber4;
}

QWidget* MyMainWindow::get_WindowNumber5()
{
return WindowNumber5;
}

QWidget* MyMainWindow::get_WindowNumber6()
{
return WindowNumber6;
}



i have test this:

// Row 0, Column 0, 1, 2. All these are 3-Rows in height, and 1-Column is Width
MyGridLayout->addWidget(fenetre.get_WindowNumber1(),0,0,3,1);
MyGridLayout->addWidget(fenetre.get_WindowNumber2(),0,1,3,1);
MyGridLayout->addWidget(fenetre.get_WindowNumber3(),0,2,3,1);

// Row 3, Column 0, 1, 2. All these are 3-Rows in height, and 1-Column is Width
MyGridLayout->addWidget(fenetre.get_WindowNumber4(),3,0,3,1);
MyGridLayout->addWidget(fenetre.get_WindowNumber5(),3,1,3,1);
MyGridLayout->addWidget(fenetre.get_WindowNumber6(),3,2,3,1);

//Buttons
// Row 0, 1, 2, 3, Column 3. All these are 1-Row in height, and 1-Column is Width
MyGridLayout->addWidget(fenetre.get_BUTTONRun() ,0,3,1,1);
MyGridLayout->addWidget(fenetre.get_BUTTONQuit() ,1,3,1,1);
MyGridLayout->addWidget(fenetre.get_BUTTONAbout() ,2,3,1,1);
MyGridLayout->addWidget(fenetre.get_BUTTONContact(),3,3,1,1);

but this is the result:

http://imageshack.us/photo/my-images/829/myplots.jpg/

i don't understand how i can make a correct ploting...

ChrisW67
27th May 2011, 01:10
Lines 8 to 21 of main.cpp should be in the MyMainWindow constructor. This should reduce the work and complexity.

You create a QWidget as container for each QwtPlot but do not set a layout on the QWidget. The QwtPlot has the container widget as its parent, so sits in the space of the QWidget but is not resized by a layout to file the space. Either have no parent QWidget and add the QwtPlot directly to the layout, or add the QwtPlot to a layout and then set that layout on the parent QWidget.

Santosh Reddy
27th May 2011, 06:15
Ok, I took a small liberty to modify your code hope you don't mine it. This would make all the plots expand to the window size, and also not allow the window to be smaller than a certain size. I checked its working on my machine.
6481
main.cpp


#include <QApplication>
#include "MyMainWindow.h"
#include <QGridLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyMainWindow fenetre;
fenetre.show();
return app.exec();
}

MyMainWindow.h


#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H

#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QMessageBox>
#include <qwt_plot.h>

class MyMainWindow : public QWidget
{
Q_OBJECT

public:
explicit MyMainWindow(QWidget* parent = 0);

private:
QPushButton *BUTTONRun;
QPushButton *BUTTONQuit;
QPushButton *BUTTONAbout;
QPushButton *BUTTONContact;

QwtPlot *myPlot1;
QwtPlot *myPlot2;
QwtPlot *myPlot3;
QwtPlot *myPlot4;
QwtPlot *myPlot5;
QwtPlot *myPlot6;
};
#endif // MYMAINWINDOW_H

MyMainWindow.cpp


#include "MyMainWindow.h"
#include <QGridLayout>
#include <QHBoxLayout>

MyMainWindow::MyMainWindow(QWidget* parent) : QWidget(parent)
{
QGridLayout* mainLayout = new QGridLayout();
setLayout(mainLayout);

myPlot1 = new QwtPlot();
myPlot2 = new QwtPlot();
myPlot3 = new QwtPlot();
myPlot4 = new QwtPlot();
myPlot5 = new QwtPlot();
myPlot6 = new QwtPlot();

myPlot1->setMinimumSize(200, 100);
myPlot2->setMinimumSize(200, 100);
myPlot3->setMinimumSize(200, 100);
myPlot4->setMinimumSize(200, 100);
myPlot5->setMinimumSize(200, 100);
myPlot6->setMinimumSize(200, 100);

QWidget* buttonWidget = new QWidget();
QGridLayout* buttonLayout = new QGridLayout();

BUTTONRun = new QPushButton("RUN");
BUTTONQuit = new QPushButton("STOP");
BUTTONAbout = new QPushButton("About");
BUTTONContact = new QPushButton("Contact");

buttonLayout->addWidget(BUTTONRun ,0,0);
buttonLayout->addWidget(BUTTONQuit ,0,1);
buttonLayout->addWidget(BUTTONAbout ,1,0);
buttonLayout->addWidget(BUTTONContact,1,1);

buttonWidget->setLayout(buttonLayout);

mainLayout->addWidget(myPlot1 ,0,0,1,1);
mainLayout->addWidget(myPlot2 ,0,1,1,1);
mainLayout->addWidget(myPlot3 ,0,2,1,1);
mainLayout->addWidget(myPlot4 ,1,0,1,1);
mainLayout->addWidget(myPlot5 ,1,1,1,1);
mainLayout->addWidget(myPlot6 ,1,2,1,1);
mainLayout->addWidget(buttonWidget ,0,3,1,1);

QObject::connect(BUTTONQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
QObject::connect(BUTTONAbout, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
}

21did21
27th May 2011, 08:49
ok! it's very nice!!!!
thanks a lot! i will try to understand your modifications.

thank you a lot ;)

21did21
27th May 2011, 22:11
thanks you it's very nice but i don't understand this:


explicit MyMainWindow(QWidget* parent = 0);

and this:


MyMainWindow::MyMainWindow(QWidget* parent) : QWidget(parent)

why you put this thing ?

Santosh Reddy
27th May 2011, 23:08
This is just to make it more maintainable, and this way it can be added to a parent. In your case as you have only one window (that is were you plot), you create main window as



MyMainWindow fenetre;
fenetre.show();


In futrue if want to have a new main window, and have the old main window as child, or even have multiple old main windows, then it is helpful

something like this will used then


MyNewMainWindow window;

MyMainWindow* childPlotWindow1(window);
MyMainWindow* childPlotWindow2(window);

// You can multiple screens in case you need.

window.show();

21did21
30th May 2011, 23:44
thank a lot !!!

Added after 44 minutes:

just one thing:

=> do you know how i can put logarithm abscisses?

ChrisW67
31st May 2011, 00:10
QwtPlot::setAxisScaleEngine() with a QwtLog10ScaleEngine. Have a look at the Bode plot example in the Qwt sources.

There is also a Qwt sub-forum here