QTabWidget
Solved
General and Desktop
-
Hi! I have a problem.
I created three tabs QPainter, QChart and QChartView, fine. But how can I work separately on these tabs?)
I mean, I want to draw something on the QPainter tab, something on the QChart tab, and something on the QChartView tab.
How do I access these tabs and write code in them? Thanks#include "mainwindow.h" #include <QTabWidget> #include <QApplication> void page1(QWidget){ } int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow *window = new QMainWindow(); window->setWindowTitle(QString::fromUtf8("MainWindow")); window->resize(400, 600); QWidget *centralWidget = new QWidget(window); QTabWidget *tabs = new QTabWidget(centralWidget); tabs->setFixedSize(400, 600); tabs->addTab(new QWidget(),"QPainter"); tabs->addTab(new QWidget(),"QChart"); tabs->addTab(new QWidget(),"QChartView"); window->setCentralWidget(centralWidget); window->show(); return app.exec(); }
-
@Troyer Either use https://doc.qt.io/qt-5/qtabwidget.html#widget to get needed widget, or do it like:
QTabWidget *tabs = new QTabWidget(centralWidget); tabs->setFixedSize(400, 600); QWidget *painter = new QWidget(); tabs->addTab(painter, "QPainter"); tabs->addTab(new QWidget(),"QChart"); QWidget *chart = new QWidget(); ...
-
@jsulm Thanks for answer.
Can you please still tell me how to make the function graph display on the tab? After all, there are several classes, and not one. Maybe they need to be grouped somehow into one class?QLineSeries *series0 = new QLineSeries(); series0->setName("line"); series0->append(0, 6); series0->append(2, 4); series0->append(3, 8); series0->append(7, 4); series0->append(10, 5); *series0 << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); QSplineSeries *series1 = new QSplineSeries(); series1->setName("spline"); series1->append(0, 6); series1->append(2, 4); series1->append(3, 8); series1->append(7, 4); series1->append(10, 5); *series1 << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); QChart *chart = new QChart(); QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing);