0
그래프를 그릴 수있는 코드는 생성자의 그래프 잘 그려진 그래프 배치되지만, 누름 버튼의 슬롯에 동일한 코드를 사용하는 동안 윈도우의 크기가 변경 될 때의 그래프, 그래프에만 그려 그릴
Qt에서 QCustomPlot을 사용할 때 창 크기가 조정 된 경우에만 그래프가 그려지며, 그 이유는 무엇입니까?
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
int month[12]={6 ,9 ,6, 5, 6, 4, 6 ,10, 6, 8, 5 ,5};
QBrush gray(Qt::gray);
ui->customPlot->setBackground(gray);
// create empty bar chart objects:
QCPBars *bar = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
bar->setName("barerative");
bar->setPen(QPen(QColor(0, 168, 140).lighter(130)));
bar->setBrush(QColor(0, 168, 140));
// prepare x axis with country labels:
QVector<double> ticks;
QVector<QString> labels;
ticks << 1 << 2 << 3 << 4 << 5 << 6 << 7<<8<<9<<10<<11<<12;
labels << "January" << "February" << "March" << "April" << "May" << "June" << "July"<<"August"<<"September"<<"October"<<"November"<<"December";
QSharedPointer<QCPAxisTickerText> textTicker(new QCPAxisTickerText);
textTicker->addTicks(ticks, labels);
ui->customPlot->xAxis->setTicker(textTicker);
ui->customPlot->xAxis->setRange(0, 8);
ui->customPlot->xAxis->grid()->setVisible(true);
ui->customPlot->xAxis->setTickLabelColor(Qt::black);
ui->customPlot->xAxis->setTickLabelFont(QFont("Times",14,2));
// prepare y axis:
ui->customPlot->yAxis->setRange(0, 15);
ui->customPlot->yAxis->setLabel("Total Sale");
ui->customPlot->yAxis->setBasePen(QPen(Qt::white));
ui->customPlot->yAxis->setTickPen(QPen(Qt::white));
ui->customPlot->yAxis->setSubTickPen(QPen(Qt::white));
ui->customPlot->yAxis->grid()->setSubGridVisible(true);
ui->customPlot->yAxis->setTickLabelColor(Qt::white);
ui->customPlot->yAxis->setLabelColor(Qt::white);
ui->customPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine));
ui->customPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine));
// Add data:
QVector<double> Data;
Data<<month[0]<<month[1]<<month[2]<<month[3]<<month[4]<<month[5]<<month[6]<<month[7]<<month[8]<<month[9]<<month[10]<<month[11];
bar->setData(ticks, Data);
}
repaint dosent work, 나는 그것을 시도했다 –
QCustomPlot 또는 부모 창보기 재 묘화? – JakeWade
customPlot.replot() worked –