Hi

I had a problem with my graph that the major x-axis is not drawn in the graph but the y-axis line is drawn (see attached image).

missingxaxis.jpg

I updated my Qwt version 5.2.3 to 6.1.6. At first the Plot Grid is missing also with the x and y -axis which was already solved in my previous post that the draw method must be overriden.

plotview.jpg

Commenting out the line of code to attach the PlotGrid removes the plot grid as well as the main y-axis.

m_plotGrid = new PlotGrid;
//m_plotGrid->attach(m_plot);

Below is the source codes that initializes the Graph elements (removed other non-related methods/implementations)

Qt Code:
  1. //PlotPanel.cpp
  2.  
  3. PlotPanel::PlotPanel(PlotStyle plotStyle, RulerType rulerType, QWidget *parent) :
  4. QWidget(parent),
  5. m_plot(0),
  6. m_plotBackground(0),
  7. m_plotGrid(0),
  8. m_plotRulerPanel(0)
  9. {
  10. setFixedSize(StyleInfo::PLOT_PANEL_WIDTH, StyleInfo::PLOT_PANEL_HEIGHT);
  11.  
  12. m_plot = new Plot(plotStyle, this);
  13. m_plot->move(PLOT_HORIZONTAL_BORDER, PLOT_TOP_BORDER);
  14.  
  15. m_plotRulerPanel = new PlotRulerPanel(rulerType, this);
  16. m_plotRulerPanel->move(PLOT_HORIZONTAL_BORDER, 0);
  17. m_plotRulerPanel->setPlot(m_plot);
  18.  
  19. m_plotBackground = new PlotBackground;
  20. m_plotBackground->attach(m_plot);
  21.  
  22. m_plotGrid = new PlotGrid;
  23. m_plotGrid->attach(m_plot);
  24.  
  25. }
To copy to clipboard, switch view to plain text mode 
The PlotPanel class is the one that initializes other plot classes that is used by the class that displays the graph.

Qt Code:
  1. //Plot.cpp
  2.  
  3. Plot::Plot(PlotStyle plotStyle, QWidget *parent) :
  4. QwtPlot(parent),
  5. m_xBottomScaleDraw(0),
  6. m_xTopScaleDraw(0),
  7. m_yLeftScaleDraw(0),
  8. m_yRightScaleDraw(0)
  9. {
  10. setFixedSize(StyleInfo::PLOT_WIDTH, StyleInfo::PLOT_HEIGHT);
  11.  
  12. ((QwtPlotCanvas*)canvas())->setFrameStyle(QFrame::Box | QFrame::Plain);
  13. ((QwtPlotCanvas*)canvas())->setLineWidth(0);
  14. ((QwtPlotCanvas*)canvas())->unsetCursor();
  15.  
  16. plotLayout()->setAlignCanvasToScales(true);
  17. plotLayout()->setSpacing(0);
  18.  
  19. for (int i=0; i<QwtPlot::axisCnt; i++)
  20. {
  21. QwtScaleWidget *scaleWidget = axisWidget(i);
  22. if (scaleWidget)
  23. {
  24. scaleWidget->setSpacing(0);
  25. scaleWidget->setMargin(0);
  26. scaleWidget->setMinBorderDist(0, 0);
  27.  
  28. QColor color;
  29. if (i == QwtPlot::yLeft)
  30. {
  31. color = StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE);
  32. }
  33. else if (i == QwtPlot::yRight)
  34. {
  35. color = StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_TWO);
  36. }
  37. else
  38. {
  39. color = StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_THREE);
  40. }
  41.  
  42. QPalette palette = scaleWidget->palette();
  43. palette.setColor(QPalette::Text, color);
  44. palette.setColor(QPalette::WindowText, color);
  45. scaleWidget->setPalette(palette);
  46. }
  47. QFont font = StyleInfo::font(StyleInfo::FONT_SIZE_SMALL);
  48. setAxisFont(i, font);
  49. }
  50.  
  51. if (plotStyle == TIME_PLOT)
  52. {
  53. m_xBottomScaleDraw = new PlotTimeScaleDraw; // will be deleted by QwtPlot
  54. }
  55. else
  56. {
  57. m_xBottomScaleDraw = new PlotScaleDraw; // will be deleted by QwtPlot
  58. }
  59. m_xBottomScaleDraw->setSpacing(X_SPACING);
  60. m_xBottomScaleDraw->setMinimumExtent(X_BOTTOM_EXTENT);
  61. setAxisScaleDraw(QwtPlot::xBottom, m_xBottomScaleDraw);
  62.  
  63. m_xTopScaleDraw = new PlotScaleDraw; // will be deleted by QwtPlot
  64. m_xTopScaleDraw->setSpacing(X_SPACING);
  65. m_xTopScaleDraw->setMinimumExtent(X_TOP_EXTENT);
  66. setAxisScaleDraw(QwtPlot::xTop, m_xTopScaleDraw);
  67.  
  68. m_yLeftScaleDraw = new PlotScaleDraw; // will be deleted by QwtPlot
  69. m_yLeftScaleDraw->setSpacing(Y_SPACING);
  70. m_yLeftScaleDraw->setMinimumExtent(Y_LEFT_EXTENT);
  71. setAxisScaleDraw(QwtPlot::yLeft, m_yLeftScaleDraw);
  72.  
  73. m_yRightScaleDraw = new PlotScaleDraw; // will be deleted by QwtPlot
  74. m_yRightScaleDraw->setSpacing(Y_SPACING);
  75. m_yRightScaleDraw->setMinimumExtent(Y_RIGHT_EXTENT);
  76. setAxisScaleDraw(QwtPlot::yRight, m_yRightScaleDraw);
  77.  
  78. for (int i=0; i<QwtPlot::axisCnt; i++)
  79. {
  80. axisScaleDraw(i)->setTickLength(QwtScaleDiv::MinorTick, TICK_LENGTH);
  81. axisScaleDraw(i)->setTickLength(QwtScaleDiv::MediumTick, TICK_LENGTH);
  82. axisScaleDraw(i)->setTickLength(QwtScaleDiv::MajorTick, TICK_LENGTH);
  83.  
  84. enableAxis(i);
  85. }
  86.  
  87. setAxisMaxMajor(QwtPlot::xBottom, MAX_MAJOR_TICKS);
  88. setAxisMaxMinor(QwtPlot::xBottom, MAX_MINOR_TICKS);
  89.  
  90. setAxisMaxMajor(QwtPlot::xTop, MAX_MAJOR_TICKS);
  91. setAxisMaxMinor(QwtPlot::xTop, MAX_MINOR_TICKS);
  92.  
  93. setAxisMaxMajor(QwtPlot::yLeft, MAX_MAJOR_TICKS);
  94. setAxisMaxMinor(QwtPlot::yLeft, MAX_MINOR_TICKS);
  95.  
  96. setAxisMaxMajor(QwtPlot::yRight, MAX_MAJOR_TICKS);
  97. setAxisMaxMinor(QwtPlot::yRight, MAX_MINOR_TICKS);
  98.  
  99. showAxis(QwtPlot::xBottom, true);
  100. showAxis(QwtPlot::xTop, false);
  101. showAxis(QwtPlot::yLeft, true);
  102. showAxis(QwtPlot::yRight, false);
  103. }
  104.  
  105. Plot::~Plot()
  106. {
  107. }
  108.  
  109. void Plot::showAxis(Axis axis, bool show)
  110. {
  111. QwtScaleDraw *scaleDraw = axisScaleDraw(axis);
  112. if (scaleDraw)
  113. {
  114. scaleDraw->enableComponent(QwtScaleDraw::Backbone, false);
  115. scaleDraw->enableComponent(QwtScaleDraw::Labels, show);
  116. scaleDraw->enableComponent(QwtScaleDraw::Ticks, show);
  117. }
  118. updateAxes();
  119. }
  120.  
  121. int Plot::scaleWidth(Axis axis) const
  122. {
  123. if ((axis >= 0) && (axis < QwtPlot::axisCnt))
  124. {
  125. const QwtScaleWidget *scaleWidget = axisWidget(axis);
  126. if (scaleWidget)
  127. {
  128. return scaleWidget->width();
  129. }
  130. }
  131. return 0;
  132. }
  133.  
  134. int Plot::scaleHeight(Axis axis) const
  135. {
  136. if ((axis >= 0) && (axis < QwtPlot::axisCnt))
  137. {
  138. const QwtScaleWidget *scaleWidget = axisWidget(axis);
  139. if (scaleWidget)
  140. {
  141. return scaleWidget->height();
  142. }
  143. }
  144. return 0;
  145. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. PlotGrid::PlotGrid() :
  2. {
  3. }
  4.  
  5. void PlotGrid::draw(QPainter *painter, const QwtScaleMap &xMap,
  6. const QwtScaleMap &yMap, const QRectF &rect) const
  7. {
  8. Q_ASSERT(painter);
  9.  
  10. painter->save();
  11.  
  12. painter->setOpacity(0.2);
  13.  
  14. painter->setPen(QPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_THREE)));
  15. drawLines(painter, rect, Qt::Vertical, xMap,
  16. m_xScaleDiv.ticks(QwtScaleDiv::MajorTick));
  17.  
  18. painter->setPen(QPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE)));
  19. drawLines(painter, rect, Qt::Horizontal, yMap,
  20. m_yScaleDiv.ticks(QwtScaleDiv::MajorTick));
  21.  
  22. painter->setOpacity(1.0);
  23.  
  24. // paint scale backbones
  25.  
  26. painter->setPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE));
  27. painter->drawLine((int)rect.left(), (int)rect.top(), (int)rect.left(), (int)rect.bottom());
  28.  
  29. painter->setPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_THREE));
  30. painter->drawLine((int)rect.left(), (int)rect.bottom(), (int)rect.right(), (int)rect.bottom());
  31.  
  32. painter->restore();
  33. }
  34.  
  35. void PlotGrid::updateScaleDiv(const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv)
  36. {
  37. m_xScaleDiv = xScaleDiv;
  38. m_yScaleDiv = yScaleDiv;
  39. }
  40.  
  41. void PlotGrid::update(void)
  42. {
  43. // todo: is there a better way to force an update??
  44. QwtPlot *qwtPlot = plot();
  45. if (qwtPlot)
  46. {
  47. QwtPlotCanvas *plotCanvas = (QwtPlotCanvas*)qwtPlot->canvas();
  48. if (plotCanvas)
  49. {
  50. plotCanvas->invalidateBackingStore();
  51. plotCanvas->update();
  52. }
  53. }
  54. }
  55.  
  56. void PlotGrid::drawLines(QPainter *painter, const QRectF &rect,
  57. Qt::Orientation orientation, const QwtScaleMap &scaleMap,
  58. const QList<double> &values) const
  59. {
  60. Q_ASSERT(painter);
  61.  
  62. const int x1 = (int)rect.left();
  63. const int x2 = (int)rect.right();
  64. const int y1 = (int)rect.top();
  65. const int y2 = (int)rect.bottom();
  66.  
  67. for (uint i = 0; i < (uint)values.count(); i++)
  68. {
  69. const int value = qRound(scaleMap.transform(values[i]));
  70. if (orientation == Qt::Horizontal)
  71. {
  72. if ((value >= y1) && (value <= y2))
  73. {
  74. painter->drawLine(x1, value, x2, value);
  75. }
  76. }
  77. else
  78. {
  79. if ((value >= x1) && (value < x2)) // suppress last line on the right
  80. {
  81. painter->drawLine(value, y1, value, y2);
  82. }
  83. }
  84. }
  85. }
To copy to clipboard, switch view to plain text mode 
The PlotGrid class displays the Plot grids as well as the x and y-axis. As you can see with qwt 6.1.6, I need to cast the qwtscalemap transform method to integer using qRound as a fix and also the QRectF value to int but I am not sure if there is a problem why the major x-axis is missing with these conversions but the y-axis is drawn okay.

Please let me know if the code I added is enough to determine why the x-axis is missing.

Regards,

olredi