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. Getting a `No alignment specified !` when setting alignment Qt::AlignCenter when adding axis using addAxis()
QtWS25 Last Chance

Getting a `No alignment specified !` when setting alignment Qt::AlignCenter when adding axis using addAxis()

Scheduled Pinned Locked Moved Solved General and Desktop
qchartqvalueaxisaligncenteraddaxis
5 Posts 2 Posters 1.3k 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.
  • S Offline
    S Offline
    Stavros Vaionitis
    wrote on last edited by
    #1

    Hi there,

    I have the following snippet of code which initializes 2 QCharts

    void InitializeCharts()
        {
            // pan
            panPositionChart = new QChart();
            panPositionChart->setTitle("Pan Position");
    
            QValueAxis *panAxisX = new QValueAxis();
            panAxisX->setTickCount(5);
            panPositionChart->addAxis(panAxisX, Qt::AlignCenter);
    
            QValueAxis *panAxisY = new QValueAxis();
            panAxisY->setTickCount(5);
            panPositionChart->addAxis(panAxisY, Qt::AlignCenter);
    
            ui->gimbalPositionPanChartview->setChart(panPositionChart);
            ui->gimbalPositionPanChartview->setRenderHint(QPainter::Antialiasing);
    
            // tilt
            tiltPositionChart = new QChart();
            tiltPositionChart->setTitle("Tilt Position");
    
            QValueAxis *tiltAxisX = new QValueAxis();
            tiltAxisX->setTickCount(5);
            tiltPositionChart->addAxis(tiltAxisX, Qt::AlignCenter);
    
            QValueAxis *tiltAxisY = new QValueAxis();
            tiltAxisY->setTickCount(5);
            tiltPositionChart->addAxis(tiltAxisY, Qt::AlignLeft);
    
            ui->gimbalPositionTiltChartview->setChart(tiltPositionChart);
            ui->gimbalPositionTiltChartview->setRenderHint(QPainter::Antialiasing);
        }
    

    For both of the QChart I want the X axis to be centered aligned. I want the Y axis to be center aligned for one of the charts and left aligned for the other. The above code is based on the QtCharts multiaxis example https://doc.qt.io/qt-6.2/qtcharts-multiaxis-example.html. When I run the above code, I get the following error

    No alignment specified !
    Segmentation fault (core dumped)
    

    If I use the Qt::AlignBottom as it is in the example, I get no error.
    If I use the Qt::AlignHCenter or Qt::AlignVCenter, I get the No alignment specified ! error.

    What am I doing wrong? Do I need to add something else?

    FYI I use the Qt 6.2.3 and for the ChartView I have compiled the designer plugin from the git repo https://code.qt.io/cgit/qt/qtcharts.git/tree/?h=6.2.3 and add it in the designers plugin directory.

    Next following how I want the chart's axis to be like and possibly there is another way to achieve this

    Pan chart
    90c42d6c-868f-471c-a4f2-9555c4b75092-image.png

    Tilt chart
    9bdcc725-6685-49b2-9200-3e3ea827d987-image.png

    Let me know if you need any more information

    Kind regards,

    Stavros

    J.HilkJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      @Stavros-Vaionitis said in Getting a `No alignment specified !` when setting alignment Qt::AlignCenter when adding axis using addAxis():

      So I suppose there is no way to move the axis as I want using the QtCharts, is this correct?

      not that I know of, but I'm by no means an expert in QtCharts 😅


      going by this SO thread, Qwt seems to have this feature

      Personally I wouldn't use QCharts for anything half way complex/custom. It is nice and easy when you want a graph for some data you have. But it's far from perfekt, and to my knowledge hasn't been actively worked on in years.

      S Offline
      S Offline
      Stavros Vaionitis
      wrote on last edited by
      #5

      Hi @J-Hilk,

      thanks for your reply and your suggestions. I was looking the Qwt myself yesterday and I used it, as you suggested, to create the charts as I wanted. Next following the function InitializeCharts() at my first comment but with the Qwt module/library now

      #include <QwtPlot>
      #include <QwtPlotScaleItem>
      
      void InitializeCharts()
      {
      	// pan
      	ui->gimbalPositionPanQwtPlot->setTitle("Pan Position");
      	ui->gimbalPositionPanQwtPlot->enableAxis(QwtAxis::YLeft, false);
      	ui->gimbalPositionPanQwtPlot->enableAxis(QwtAxis::XBottom, false);
      	ui->gimbalPositionPanQwtPlot->enableAxis(QwtAxis::YLeft, false);
      	ui->gimbalPositionPanQwtPlot->enableAxis(QwtAxis::XBottom, false);
      	ui->gimbalPositionPanQwtPlot->setAxisScale(QwtAxis::YLeft, -90.0, 90.0);
      	ui->gimbalPositionPanQwtPlot->setAxisScale(QwtAxis::XBottom, -90.0, 90.0);
      
      	QwtPlotScaleItem *panVerticalAxisScale = new QwtPlotScaleItem(QwtScaleDraw::RightScale, 0.0);
      	panVerticalAxisScale->attach(ui->gimbalPositionPanQwtPlot);
      	QwtPlotScaleItem *panHorizontalAxisScale = new QwtPlotScaleItem(QwtScaleDraw::BottomScale, 0.0);
      	panHorizontalAxisScale->attach(ui->gimbalPositionPanQwtPlot);
      
      	// tilt
      	ui->gimbalPositionTiltQwtPlot->setTitle("Tilt Position");
      	ui->gimbalPositionTiltQwtPlot->enableAxis(QwtAxis::YLeft, false);
      	ui->gimbalPositionTiltQwtPlot->enableAxis(QwtAxis::XBottom, false);
      	ui->gimbalPositionTiltQwtPlot->enableAxis(QwtAxis::YLeft, false);
      	ui->gimbalPositionTiltQwtPlot->enableAxis(QwtAxis::XBottom, false);
      	ui->gimbalPositionTiltQwtPlot->setAxisScale(QwtAxis::YLeft, -90.0, 90.0);
      	ui->gimbalPositionTiltQwtPlot->setAxisScale(QwtAxis::XBottom, 0.0, 90.0);
      
      	QwtPlotScaleItem *tiltVerticalAxisScale = new QwtPlotScaleItem(QwtScaleDraw::RightScale, 0.0);
      	tiltVerticalAxisScale->attach(ui->gimbalPositionTiltQwtPlot);
      	QwtPlotScaleItem *tiltHorizontalAxisScale = new QwtPlotScaleItem(QwtScaleDraw::BottomScale, 0.0);
      	tiltHorizontalAxisScale->attach(ui->gimbalPositionTiltQwtPlot);
      }
      

      The output would look like the following

      0936b8d6-3d0d-49ec-8f58-ed1cbd7b9653-image.png

      which is close enough for me of what I wanted to achieve.

      Thanks again @J-Hilk for your time replying to my issue.

      Kind regards,

      Stavros

      1 Reply Last reply
      1
      • S Stavros Vaionitis

        Hi there,

        I have the following snippet of code which initializes 2 QCharts

        void InitializeCharts()
            {
                // pan
                panPositionChart = new QChart();
                panPositionChart->setTitle("Pan Position");
        
                QValueAxis *panAxisX = new QValueAxis();
                panAxisX->setTickCount(5);
                panPositionChart->addAxis(panAxisX, Qt::AlignCenter);
        
                QValueAxis *panAxisY = new QValueAxis();
                panAxisY->setTickCount(5);
                panPositionChart->addAxis(panAxisY, Qt::AlignCenter);
        
                ui->gimbalPositionPanChartview->setChart(panPositionChart);
                ui->gimbalPositionPanChartview->setRenderHint(QPainter::Antialiasing);
        
                // tilt
                tiltPositionChart = new QChart();
                tiltPositionChart->setTitle("Tilt Position");
        
                QValueAxis *tiltAxisX = new QValueAxis();
                tiltAxisX->setTickCount(5);
                tiltPositionChart->addAxis(tiltAxisX, Qt::AlignCenter);
        
                QValueAxis *tiltAxisY = new QValueAxis();
                tiltAxisY->setTickCount(5);
                tiltPositionChart->addAxis(tiltAxisY, Qt::AlignLeft);
        
                ui->gimbalPositionTiltChartview->setChart(tiltPositionChart);
                ui->gimbalPositionTiltChartview->setRenderHint(QPainter::Antialiasing);
            }
        

        For both of the QChart I want the X axis to be centered aligned. I want the Y axis to be center aligned for one of the charts and left aligned for the other. The above code is based on the QtCharts multiaxis example https://doc.qt.io/qt-6.2/qtcharts-multiaxis-example.html. When I run the above code, I get the following error

        No alignment specified !
        Segmentation fault (core dumped)
        

        If I use the Qt::AlignBottom as it is in the example, I get no error.
        If I use the Qt::AlignHCenter or Qt::AlignVCenter, I get the No alignment specified ! error.

        What am I doing wrong? Do I need to add something else?

        FYI I use the Qt 6.2.3 and for the ChartView I have compiled the designer plugin from the git repo https://code.qt.io/cgit/qt/qtcharts.git/tree/?h=6.2.3 and add it in the designers plugin directory.

        Next following how I want the chart's axis to be like and possibly there is another way to achieve this

        Pan chart
        90c42d6c-868f-471c-a4f2-9555c4b75092-image.png

        Tilt chart
        9bdcc725-6685-49b2-9200-3e3ea827d987-image.png

        Let me know if you need any more information

        Kind regards,

        Stavros

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @Stavros-Vaionitis

        thats because QCharts only accepts a limited amount of alignments:

        void QAbstractAxisPrivate::setAlignment(Qt::Alignment alignment)
        {
            switch (alignment) {
            case Qt::AlignTop:
            case Qt::AlignBottom:
                m_orientation = Qt::Horizontal;
                break;
            case Qt::AlignLeft:
            case Qt::AlignRight:
                m_orientation = Qt::Vertical;
                break;
            default:
                qWarning("No alignment specified !");
                break;
            }
            m_alignment = alignment;
        }
        

        https://github.com/qt/qtcharts/blob/dev/src/charts/axis/qabstractaxis.cpp


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        S 1 Reply Last reply
        1
        • J.HilkJ J.Hilk

          @Stavros-Vaionitis

          thats because QCharts only accepts a limited amount of alignments:

          void QAbstractAxisPrivate::setAlignment(Qt::Alignment alignment)
          {
              switch (alignment) {
              case Qt::AlignTop:
              case Qt::AlignBottom:
                  m_orientation = Qt::Horizontal;
                  break;
              case Qt::AlignLeft:
              case Qt::AlignRight:
                  m_orientation = Qt::Vertical;
                  break;
              default:
                  qWarning("No alignment specified !");
                  break;
              }
              m_alignment = alignment;
          }
          

          https://github.com/qt/qtcharts/blob/dev/src/charts/axis/qabstractaxis.cpp

          S Offline
          S Offline
          Stavros Vaionitis
          wrote on last edited by Stavros Vaionitis
          #3

          @J-Hilk

          Great thanks for your prompt reply and this info. So it seems that the alignment in the chart axis is actually orientation.

          So I suppose there is no way to move the axis as I want using the QtCharts, is this correct?

          J.HilkJ 1 Reply Last reply
          0
          • S Stavros Vaionitis

            @J-Hilk

            Great thanks for your prompt reply and this info. So it seems that the alignment in the chart axis is actually orientation.

            So I suppose there is no way to move the axis as I want using the QtCharts, is this correct?

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #4

            @Stavros-Vaionitis said in Getting a &#x60;No alignment specified !&#x60; when setting alignment Qt::AlignCenter when adding axis using addAxis():

            So I suppose there is no way to move the axis as I want using the QtCharts, is this correct?

            not that I know of, but I'm by no means an expert in QtCharts 😅


            going by this SO thread, Qwt seems to have this feature

            Personally I wouldn't use QCharts for anything half way complex/custom. It is nice and easy when you want a graph for some data you have. But it's far from perfekt, and to my knowledge hasn't been actively worked on in years.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            S 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @Stavros-Vaionitis said in Getting a &#x60;No alignment specified !&#x60; when setting alignment Qt::AlignCenter when adding axis using addAxis():

              So I suppose there is no way to move the axis as I want using the QtCharts, is this correct?

              not that I know of, but I'm by no means an expert in QtCharts 😅


              going by this SO thread, Qwt seems to have this feature

              Personally I wouldn't use QCharts for anything half way complex/custom. It is nice and easy when you want a graph for some data you have. But it's far from perfekt, and to my knowledge hasn't been actively worked on in years.

              S Offline
              S Offline
              Stavros Vaionitis
              wrote on last edited by
              #5

              Hi @J-Hilk,

              thanks for your reply and your suggestions. I was looking the Qwt myself yesterday and I used it, as you suggested, to create the charts as I wanted. Next following the function InitializeCharts() at my first comment but with the Qwt module/library now

              #include <QwtPlot>
              #include <QwtPlotScaleItem>
              
              void InitializeCharts()
              {
              	// pan
              	ui->gimbalPositionPanQwtPlot->setTitle("Pan Position");
              	ui->gimbalPositionPanQwtPlot->enableAxis(QwtAxis::YLeft, false);
              	ui->gimbalPositionPanQwtPlot->enableAxis(QwtAxis::XBottom, false);
              	ui->gimbalPositionPanQwtPlot->enableAxis(QwtAxis::YLeft, false);
              	ui->gimbalPositionPanQwtPlot->enableAxis(QwtAxis::XBottom, false);
              	ui->gimbalPositionPanQwtPlot->setAxisScale(QwtAxis::YLeft, -90.0, 90.0);
              	ui->gimbalPositionPanQwtPlot->setAxisScale(QwtAxis::XBottom, -90.0, 90.0);
              
              	QwtPlotScaleItem *panVerticalAxisScale = new QwtPlotScaleItem(QwtScaleDraw::RightScale, 0.0);
              	panVerticalAxisScale->attach(ui->gimbalPositionPanQwtPlot);
              	QwtPlotScaleItem *panHorizontalAxisScale = new QwtPlotScaleItem(QwtScaleDraw::BottomScale, 0.0);
              	panHorizontalAxisScale->attach(ui->gimbalPositionPanQwtPlot);
              
              	// tilt
              	ui->gimbalPositionTiltQwtPlot->setTitle("Tilt Position");
              	ui->gimbalPositionTiltQwtPlot->enableAxis(QwtAxis::YLeft, false);
              	ui->gimbalPositionTiltQwtPlot->enableAxis(QwtAxis::XBottom, false);
              	ui->gimbalPositionTiltQwtPlot->enableAxis(QwtAxis::YLeft, false);
              	ui->gimbalPositionTiltQwtPlot->enableAxis(QwtAxis::XBottom, false);
              	ui->gimbalPositionTiltQwtPlot->setAxisScale(QwtAxis::YLeft, -90.0, 90.0);
              	ui->gimbalPositionTiltQwtPlot->setAxisScale(QwtAxis::XBottom, 0.0, 90.0);
              
              	QwtPlotScaleItem *tiltVerticalAxisScale = new QwtPlotScaleItem(QwtScaleDraw::RightScale, 0.0);
              	tiltVerticalAxisScale->attach(ui->gimbalPositionTiltQwtPlot);
              	QwtPlotScaleItem *tiltHorizontalAxisScale = new QwtPlotScaleItem(QwtScaleDraw::BottomScale, 0.0);
              	tiltHorizontalAxisScale->attach(ui->gimbalPositionTiltQwtPlot);
              }
              

              The output would look like the following

              0936b8d6-3d0d-49ec-8f58-ed1cbd7b9653-image.png

              which is close enough for me of what I wanted to achieve.

              Thanks again @J-Hilk for your time replying to my issue.

              Kind regards,

              Stavros

              1 Reply Last reply
              1

              • Login

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