добавить диаграмму в QTabWidget - PullRequest
0 голосов
/ 15 мая 2018

Я хочу прочитать текстовый файл формы данных и добавить диаграмму чисел в tabWidget (tab1), но при показе был открыт новый виджет, как я могу это исправить?

void mainWindow::readfile(){

    QFile config(":/new/prefix1/3.txt");
    config.open(QIODevice::ReadOnly);
    if(config.isOpen()){
        QTextStream stream(&config);
        while (!stream.atEnd()){
         line = stream.readLine().split('\t');
        //qDebug()<<line;
        bool allOk(true);
        bool ok;
        for (int x = 0; x <= line.count()-1 && allOk; x++) {
        val.append(line.at(x).toInt(&ok));
        allOk &= ok;
            }
        }
}
    else
        qDebug()<<"not opened";
     ui->stackedWidget->setCurrentIndex(8);
     on_ecg_destroyed();
}

void mainWindow::on_ecg_destroyed()
{
    QLineSeries *series = new QLineSeries();
        for(int y=0;y<288;y++)
            series->append(y,val[y]);

    QChart *chart = new QChart();
    chart->legend()->hide();
    chart->addSeries(series);
    chart->createDefaultAxes();
    chart->setTitle("line chart");
     QChartView *chartView = new QChartView(chart);
    chartView->setRenderHint(QPainter::Antialiasing);
    setCentralWidget(chartView);
    resize(400, 300);
    show();
}

Я используюQStackWidget для определения страниц, и на одной из них (страницах) я использую QTabWidget с четырьмя вкладками и хочу создать график на вкладке 1. QTabWidget расположен в QStackWidget index 8, После прочтенияфайл, покажите диаграмму на стр. 8 в tab1.

1 Ответ

0 голосов
/ 15 мая 2018

В вашем коде вам нужно добавить chartview, чтобы исправить вкладку QTabWidget, вы можете создать макет, добавить chartview к созданному макету, а затем установить макет tab1 в этот новый макет:

QChart *chart = new QChart();
chart->legend()->hide();
chart->addSeries(series);
chart->createDefaultAxes();
chart->setTitle("line chart");
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
// create layout
QGridLayout layout;
layout.addWidget(chartView);
this->ui->tab1->setLayout(&layout);
// position view to chartview
this->ui->stackedWidget->setCurrentIndex(8);
this->ui->tabWidget->setCurrentIndex(this->ui->tabWidget->indexOf(this->ui->tab1));
...