PDA

View Full Version : use a QWT layout with QCustomPlot



bandito
11th June 2016, 19:22
I am a little lost as to how to use a layout manager with QCP. I understand how to add rows and columns in QCP but I need to add a QListView to list come text to the right of my QCP graph. Since QCP can't add QWT elements (at least not to my knowledge) I need to use a QWT layout manager. I would like to add a QVBoxLayout to this code with. Thanks.

(mainwindow.cpp)

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow){
ui->setupUi(this);
MainWindow::makePlot();
}

...............



void MainWindow::makePlot(QString stock){
// set the title
ui->customPlot->plotLayout()->insertRow(0);
QCPPlotTitle *plotTitle = new QCPPlotTitle(ui->customPlot);
plotTitle->setMargins(QMargins(0,0,0,0));
plotTitle->setTextColor(QColor(255,255,255));
plotTitle->setFont(QFont(QFont().family(), 12));
plotTitle->setText("hello world");
ui->customPlot->plotLayout()->addElement(0, 0, plotTitle);
ui->customPlot->setBackground(QBrush(QColor(70,70,70)));

QCPFinancial *candlesticks = new QCPFinancial(ui->customPlot->xAxis, ui->customPlot->yAxis);
...............................................

(main.cpp)

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}

(mainwindow.h)

namespace Ui {
class MainWindow;
}



class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void makePlot(QString stock);

private:
Ui::MainWindow *ui;
protected:

};




#endif // MAINWINDOW_H

anda_skoa
11th June 2016, 19:50
I don't know that this has to do with QWT, but if you want a QListView side by side with the QCustomPlot widget, you add both to a QHBoxLayout.

Cheers,
_