在QTabWidget中添加图表
我想从文本文件中读取数据,并在在QTabWidget中添加图表,qt,qtabwidget,Qt,Qtabwidget,我想从文本文件中读取数据,并在tabWidget(tab1)中添加数字图表 但当显示时,新的小部件已打开,我如何修复此问题 void mainWindow::readfile(){ QFile config(":/new/prefix1/3.txt"); config.open(QIODevice::ReadOnly); if(config.isOpen()){ QTextStream stream(&config); while
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();
}
void主窗口::readfile(){
QFile配置(“:/new/prefix1/3.txt”);
config.open(QIODevice::ReadOnly);
if(config.isOpen()){
QTextStream流(&config);
而(!stream.atEnd()){
line=stream.readLine().split('\t');
//qDebug()添加系列(系列);
图表->CreateDefaultAxis();
图表->设置标题(“折线图”);
QChartView*图表视图=新的QChartView(图表);
图表视图->SetRenderInt(QPaint::抗锯齿);
setCentralWidget(图表视图);
调整大小(400300);
show();
}
我使用QStackWidget
来定义页面,在其中一个(页面)中,我使用带有四个选项卡的QTabWidget
,我想在选项卡1中创建一个图形。
QTabWidget
位于QStackWidget
索引8中,
阅读文件后,在代码中的
tab1
中显示第8页的图表。您需要添加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));