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. QChartView position
Forum Updated to NodeBB v4.3 + New Features

QChartView position

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.2k Views
  • 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.
  • M Offline
    M Offline
    mateuscrv
    wrote on last edited by
    #1

    Hello everyone,

    I'm trying to create a screen to show a chart, but I don't know how set the position of the QChartView. In the picture bellow, the chart suppose to be between the line gray circuled in red, and the down of the screen.

    0_1556228531025_c4cdbe94-6654-4ef5-8128-b99aaebfc788-image.png

    The code is below, you can see I tried some properties that are commented out, but not worked.

    // Assign names to the set of bars used
                QBarSet *set0 = new QBarSet("Aprovados");
                QBarSet *set1 = new QBarSet("Reprovados");
                /*QBarSet *set2 = new QBarSet("Segura");
                QBarSet *set3 = new QBarSet("Simmons");
                QBarSet *set4 = new QBarSet("Trout");*/
    
                // Assign values for each bar
                *set0 << 10;
                *set1 << 7;
         
    
    
                // Add all sets of data to the chart as a whole
                // 1. Bar Chart
                QBarSeries *series = new QBarSeries();
    
                // 2. Stacked bar chart
                // QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries();
                series->append(set0);
                series->append(set1);
                
    
                // Used to define the bar chart to display, title
                // legend,
                QChart *chart = new QChart();
    
                // Add the chart
                chart->addSeries(series);
    
                // Set title
                chart->setTitle("Quantidade de Acessos Aprovados/Reprovados");
    
                // Define starting animation
                // NoAnimation, GridAxisAnimations, SeriesAnimations
                chart->setAnimationOptions(QChart::AllAnimations);
    
                // Holds the category titles
                QStringList categories;
                categories << "Aprovados/Reprovados"; //<< "Reprovados";
    
                // Adds categories to the axes
                QBarCategoryAxis *axis = new QBarCategoryAxis();
                axis->append(categories);
                chart->createDefaultAxes();
    
                // 1. Bar chart
                chart->setAxisX(axis, series);
    
                // 2. Stacked Bar chart
                // chart->setAxisY(axis, series);
    
                // Define where the legend is displayed
                chart->legend()->setVisible(true);
                chart->legend()->setAlignment(Qt::AlignBottom);
    
                // Used to display the chart
                QChartView *chartView = new QChartView(chart);
                chartView->setRenderHint(QPainter::Antialiasing);
                //chartView->setFixedSize(720,400);
                //chartView->setGeometry(0,400,720,400);
    
                // Used to change the palette
                QPalette pal = qApp->palette();
    
                // Change the color around the chart widget and text
                pal.setColor(QPalette::Window, QRgb(0xffffff));
                pal.setColor(QPalette::WindowText, QRgb(0x404044));
    
                // Apply palette changes to the application
                qApp->setPalette(pal);
    
        /*QMainWindow window;
    
                // Set the main window widget
    
    
                window.setCentralWidget(chartView);
                window.resize(1020, 600);
                window.show();*/
    
                QGridLayout *mainLayout = new QGridLayout;
                mainLayout->addWidget(chartView, 200, 600);
                setLayout(mainLayout);
    

    Any help is usefull. Thanks a lot!

    1 Reply Last reply
    0
    • KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by
      #2

      @mateuscrv
      The chartview has been added in a QGridLayout, so the QGridlayout have the control of chartview Size and Position attributes.
      You could change the position of this view by change the content margins of this QGridLayout.
      https://doc.qt.io/qt-5/qlayout.html#setContentsMargins
      Or adding spacers with fixed sizes.

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      1 Reply Last reply
      1
      • W Offline
        W Offline
        Willie33
        wrote on last edited by Willie33
        #3

        In the meantime I thought the dynamic-spline-example would guide me, but it failed. I also found, that there is as well a scroll() for the QChart itself. But I really have no clue about what it does, since i can not, or at least I didn't find out how, zoom only in x-direction an then scroll along UPSers

        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