Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAbstractScrollArea ScrollbarPolicy with a customized qchartview
Forum Updated to NodeBB v4.3 + New Features

QAbstractScrollArea ScrollbarPolicy with a customized qchartview

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 2.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vorlket
    wrote on last edited by
    #1

    To have a zoomable line chart, I created a view class by replicating the qchartview class in the zoomline example (http://doc.qt.io/qt-5/qtcharts-zoomlinechart-example.html), with the difference being removal of the qgraphicsscene variable. With this view class, I tried to generate the (horizontal) scrollbar via the scrollbar policy. This trick or method works with qgraphicsview but doesn't with the created view class. What would be the likely causes?

    FlotisableF 1 Reply Last reply
    0
    • V vorlket

      To have a zoomable line chart, I created a view class by replicating the qchartview class in the zoomline example (http://doc.qt.io/qt-5/qtcharts-zoomlinechart-example.html), with the difference being removal of the qgraphicsscene variable. With this view class, I tried to generate the (horizontal) scrollbar via the scrollbar policy. This trick or method works with qgraphicsview but doesn't with the created view class. What would be the likely causes?

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      @vorlket
      what scrollbar policy you set ? maybe the chart is not big enough, so it does not show the scrollbar.

      1 Reply Last reply
      1
      • V Offline
        V Offline
        vorlket
        wrote on last edited by
        #3

        Doubt it. Tried both 'asneeded' and 'alwayson' where the latter generates scrollbar detached from the chart, i.e. it doesn't scroll with the chart.

        FlotisableF 1 Reply Last reply
        0
        • V vorlket

          Doubt it. Tried both 'asneeded' and 'alwayson' where the latter generates scrollbar detached from the chart, i.e. it doesn't scroll with the chart.

          FlotisableF Offline
          FlotisableF Offline
          Flotisable
          wrote on last edited by
          #4

          @vorlket
          I have tried make a simple program using the QChartView and it works fine.
          but it seems that the default scrollbar policy is ScrollBarAlwaysOff.
          can you provide your code so that we can have more information.

          1 Reply Last reply
          1
          • V Offline
            V Offline
            vorlket
            wrote on last edited by vorlket
            #5

            The view class is based on the QChartView class with the following changes:

            In Qt/5.7/Src/qtcharts/src/charts/qchartview_p.h, removed line 66: QGraphicsScene *m_scene;

            In Qt/5.7/Src/qtcharts/src/charts/qchartview.cpp, replaced line 293: m_scene->removeItem(m_chart); with m_chart->scene()->removeItem(m_chart);

            In Qt/5.7/Src/qtcharts/src/charts/qchartview.cpp, removed line 295: m_scene->addItem(m_chart);

            With the changed view class I made the following change to the zoom line example:
            In chartview.h (http://doc.qt.io/qt-5/qtcharts-zoomlinechart-chartview-h.html), added constructor ChartView(QWidget *parent = 0);

            ui_mainwindow.h: graphicsView object is Graphics View widget promoted to the ChartView (ZoomableView in my code) in the zoom line example.

            #ifndef UI_MAINWINDOW_H
            #define UI_MAINWINDOW_H
            
            #include <QtCore/QVariant>
            #include <QtWidgets/QAction>
            #include <QtWidgets/QApplication>
            #include <QtWidgets/QButtonGroup>
            #include <QtWidgets/QHeaderView>
            #include <QtWidgets/QMainWindow>
            #include <QtWidgets/QMenuBar>
            #include <QtWidgets/QStatusBar>
            #include <QtWidgets/QToolBar>
            #include <QtWidgets/QWidget>
            #include "zoomableview.h"
            
            QT_BEGIN_NAMESPACE
            
            class Ui_MainWindow
            {
            public:
                QWidget *centralWidget;
                ZoomableView *graphicsView;
                QMenuBar *menuBar;
                QToolBar *mainToolBar;
                QStatusBar *statusBar;
            
                void setupUi(QMainWindow *MainWindow)
                {
                    if (MainWindow->objectName().isEmpty())
                        MainWindow->setObjectName(QStringLiteral("MainWindow"));
                    MainWindow->resize(1076, 802);
                    centralWidget = new QWidget(MainWindow);
                    centralWidget->setObjectName(QStringLiteral("centralWidget"));
                    graphicsView = new ZoomableView(centralWidget);
                    graphicsView->setObjectName(QStringLiteral("graphicsView"));
                    graphicsView->setGeometry(QRect(10, 10, 1051, 721));
                    graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
                    graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
                    graphicsView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustIgnored);
                    graphicsView->setSceneRect(QRectF(0, 0, 0, 0));
                    MainWindow->setCentralWidget(centralWidget);
                    menuBar = new QMenuBar(MainWindow);
                    menuBar->setObjectName(QStringLiteral("menuBar"));
                    menuBar->setGeometry(QRect(0, 0, 1076, 20));
                    MainWindow->setMenuBar(menuBar);
                    mainToolBar = new QToolBar(MainWindow);
                    mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
                    MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
                    statusBar = new QStatusBar(MainWindow);
                    statusBar->setObjectName(QStringLiteral("statusBar"));
                    MainWindow->setStatusBar(statusBar);
            
                    retranslateUi(MainWindow);
            
                    QMetaObject::connectSlotsByName(MainWindow);
                } // setupUi
            
                void retranslateUi(QMainWindow *MainWindow)
                {
                    MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
                } // retranslateUi
            
            };
            
            namespace Ui {
                class MainWindow: public Ui_MainWindow {};
            } // namespace Ui
            
            QT_END_NAMESPACE
            
            #endif // UI_MAINWINDOW_H
            
            FlotisableF 1 Reply Last reply
            0
            • V vorlket

              The view class is based on the QChartView class with the following changes:

              In Qt/5.7/Src/qtcharts/src/charts/qchartview_p.h, removed line 66: QGraphicsScene *m_scene;

              In Qt/5.7/Src/qtcharts/src/charts/qchartview.cpp, replaced line 293: m_scene->removeItem(m_chart); with m_chart->scene()->removeItem(m_chart);

              In Qt/5.7/Src/qtcharts/src/charts/qchartview.cpp, removed line 295: m_scene->addItem(m_chart);

              With the changed view class I made the following change to the zoom line example:
              In chartview.h (http://doc.qt.io/qt-5/qtcharts-zoomlinechart-chartview-h.html), added constructor ChartView(QWidget *parent = 0);

              ui_mainwindow.h: graphicsView object is Graphics View widget promoted to the ChartView (ZoomableView in my code) in the zoom line example.

              #ifndef UI_MAINWINDOW_H
              #define UI_MAINWINDOW_H
              
              #include <QtCore/QVariant>
              #include <QtWidgets/QAction>
              #include <QtWidgets/QApplication>
              #include <QtWidgets/QButtonGroup>
              #include <QtWidgets/QHeaderView>
              #include <QtWidgets/QMainWindow>
              #include <QtWidgets/QMenuBar>
              #include <QtWidgets/QStatusBar>
              #include <QtWidgets/QToolBar>
              #include <QtWidgets/QWidget>
              #include "zoomableview.h"
              
              QT_BEGIN_NAMESPACE
              
              class Ui_MainWindow
              {
              public:
                  QWidget *centralWidget;
                  ZoomableView *graphicsView;
                  QMenuBar *menuBar;
                  QToolBar *mainToolBar;
                  QStatusBar *statusBar;
              
                  void setupUi(QMainWindow *MainWindow)
                  {
                      if (MainWindow->objectName().isEmpty())
                          MainWindow->setObjectName(QStringLiteral("MainWindow"));
                      MainWindow->resize(1076, 802);
                      centralWidget = new QWidget(MainWindow);
                      centralWidget->setObjectName(QStringLiteral("centralWidget"));
                      graphicsView = new ZoomableView(centralWidget);
                      graphicsView->setObjectName(QStringLiteral("graphicsView"));
                      graphicsView->setGeometry(QRect(10, 10, 1051, 721));
                      graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
                      graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
                      graphicsView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustIgnored);
                      graphicsView->setSceneRect(QRectF(0, 0, 0, 0));
                      MainWindow->setCentralWidget(centralWidget);
                      menuBar = new QMenuBar(MainWindow);
                      menuBar->setObjectName(QStringLiteral("menuBar"));
                      menuBar->setGeometry(QRect(0, 0, 1076, 20));
                      MainWindow->setMenuBar(menuBar);
                      mainToolBar = new QToolBar(MainWindow);
                      mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
                      MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
                      statusBar = new QStatusBar(MainWindow);
                      statusBar->setObjectName(QStringLiteral("statusBar"));
                      MainWindow->setStatusBar(statusBar);
              
                      retranslateUi(MainWindow);
              
                      QMetaObject::connectSlotsByName(MainWindow);
                  } // setupUi
              
                  void retranslateUi(QMainWindow *MainWindow)
                  {
                      MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
                  } // retranslateUi
              
              };
              
              namespace Ui {
                  class MainWindow: public Ui_MainWindow {};
              } // namespace Ui
              
              QT_END_NAMESPACE
              
              #endif // UI_MAINWINDOW_H
              
              FlotisableF Offline
              FlotisableF Offline
              Flotisable
              wrote on last edited by
              #6

              @vorlket
              do you remove q_ptr->setScene in QChartViewPrivate's constructor?
              I wonder why you don't create view class by inheriting QChart but to modify QChart's source code.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vorlket
                wrote on last edited by
                #7

                The scrollbar doesn't seem to work with QchartView while does with Graphics View Framework, i.e. chart, scene, and view are decoupled.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved