[Interest] QwtPlot in QGridLayout

Sujan Dasmahapatra sdh at lmwindpower.com
Thu May 3 11:24:31 CEST 2012


I want to create a some plots on the QGridLayout. 

I have a QWidget which has a pushbutton and another QWidget called
canvas.

In the canvas I have a QGridLayout.

When user presses the  pushbutton it should create a QWidget and this
widget will have my plot and a legend. They will be appended in  2
columns and multiple rows.

 

//please check this code snippet

 

//sheet.h

class CSheet : public QWidget

{

Q_OBJECT

Public:

CSheet(QWidget *parent=0);

~CSheet();

QWidget *canvas;

QPushButton *addChartPB;

QGridLayout  *layout;

 

QList <QWidget *> plotWidgets;

QList  <QwtPlot *> plots;

QList <QWidget *> legends;

 

int row, column;

 

private slots:

void addChart();

 

};

 

//sheet.cpp

 

CSheet::CSheet(QWidget *parent):QWidget(parent), row(0), column(0)

{

                setGeometry(0,0,800,600);         

 

                addChartPB = new QWidget("Add chart", this);

                addChartPB->setGeometry(5,5,100,25);

                addChartPB->show();

 

                canvas = new QWidget(this);

                canvas->setGeometry(5,35,width()-10, height()-40);

                canvas->show();

                                

                layout = new QGridLayout(canvas);

                canvas->setLayout(layout);

}

 

CSheet::~CSheet()

{

} 

 

void CSheet::addChart()

{

                plotWidgets.append(new QWidget(canvas));

 

                plots.append(new QwtPlot(plotWidgets.last()));

 

                legends.append(new QWidget(plotWidgets.last()));

 

                layout->addWidget(plotWidgets.last(), row, column);

 

                if(column==0)

                                column++;

                else

                                column--;            

                if(plotsWidgets.count()%2==0)

                row++;

}

 

 

With this piece of code my plots and legends nothing is visible. Can
anyone help in getting whats going wrong in this. Thanks a lot Sujan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120503/a60246b9/attachment.html>


More information about the Interest mailing list