Results 1 to 4 of 4

Thread: Lining up Inner and Outer Ticks

  1. #1
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Lining up Inner and Outer Ticks

    I've got a problem and I realize it is a long shot at being able to fix without seeing code, but here's the deal:

    I have inner ticks (QwtPlotScaleItem) and outer ticks plotting together, but when I first render my plot, the inner/outer scales are not lined up. The instant I resize my plot, they shift and line up correctly.

    I am using my own versions of QwtScaleDraw's, but I am using the standard QwtScaleWidget's though. I have setScaleDivFromAxis (true) and have plotLayout ()->setAlignCanvasToScales (true) also set. I'm not even sure if that's relevant.

    I also have all axes enabled, but in some cases I disable the labels and ticks. In every case where they are not lined up, it is when the major tick is not at the beginning of the axis. I also always use setAttribute (QwtScaleEngine::Floating, true) on the scale engine which I set for every axis. I only use linear and log scales.

    I feel like it might be an order of operations thing that I am not getting, but I really have no idea of where to look at trying to debug this.

    Anyway, like I said, this may be a long shot, but if you have any ideas, I'd love to hear them!

    Thanks,
    Joey

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,313
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Lining up Inner and Outer Ticks

    I'm aware of a bug that can be responsible for 1 pixel difference between an inner and outer scale - but your situation looks more like an update problem.
    Hard to say something useful without having a demo application.

    Uwe

  3. #3
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Lining up Inner and Outer Ticks

    Ok! I think I made an example program by merging the timescale example in playground with my program.

    When you start it up, the scales on the left are a little off. You resize the plot and they are fine.

    Joey

    Here's my diff:

    Qt Code:
    1. Index: mainwindow.cpp
    2. ===================================================================
    3. --- mainwindow.cpp (revision 1453)
    4. +++ mainwindow.cpp (working copy)
    5. @@ -9,7 +9,7 @@
    6. QMainWindow( parent )
    7. {
    8. Settings settings;
    9. - settings.startDateTime = QDateTime( QDate( 2012, 3, 10 ), QTime( 0, 5, 0 ) );
    10. + settings.startDateTime = QDateTime( QDate( 2011, 1, 17 ), QTime( 0, 5, 0 ) );
    11. settings.endDateTime = QDateTime( QDate( 2012, 3, 10 ), QTime( 0, 6, 0, 5 ) );
    12. settings.maxMajorSteps = 10;
    13. settings.maxMinorSteps = 8;
    14. Index: plot.cpp
    15. ===================================================================
    16. --- plot.cpp (revision 1453)
    17. +++ plot.cpp (working copy)
    18. @@ -5,6 +5,7 @@
    19. #include "timescaledraw.h"
    20. #include <qwt_plot_panner.h>
    21. #include <qwt_plot_magnifier.h>
    22. +#include <qwt_plot_scaleitem.h>
    23.  
    24. Plot::Plot( QWidget *parent ):
    25. QwtPlot( parent )
    26. @@ -25,9 +26,53 @@
    27. const bool on = ( i == axis );
    28. panner->setAxisEnabled( i, on );
    29. magnifier->setAxisEnabled( i, on );
    30. + _innerTicks [i] = NULL;
    31. }
    32. + InnerTicks (QwtPlot::yLeft, true, true);
    33. + InnerTicks (QwtPlot::xBottom, true, true);
    34. }
    35.  
    36. +void
    37. +Plot::InnerTicks (int axisId, bool showMajor, bool showMinor)
    38. +{
    39. + QwtScaleDraw::Alignment align;
    40. + if (showMajor || showMinor) {
    41. + if (_innerTicks [axisId] == NULL) {
    42. + _innerTicks [axisId] = new QwtPlotScaleItem ();
    43. + switch (axisId) {
    44. + case QwtPlot::yLeft : align = QwtScaleDraw::RightScale;
    45. + _innerTicks [axisId]->setAxes (QwtPlot::xBottom, QwtPlot::yLeft);
    46. + break;
    47. + case QwtPlot::yRight : align = QwtScaleDraw::LeftScale;
    48. + _innerTicks [axisId]->setAxes (QwtPlot::xBottom, QwtPlot::yRight);
    49. + break;
    50. + case QwtPlot::xBottom : align = QwtScaleDraw::TopScale;
    51. + _innerTicks [axisId]->setAxes (QwtPlot::xBottom, QwtPlot::yLeft);
    52. + break;
    53. + case QwtPlot::xTop : align = QwtScaleDraw::BottomScale;
    54. + if (axisScaleDraw (axisId)->hasComponent (QwtAbstractScaleDraw::Labels))
    55. + _innerTicks [axisId]->setAxes (QwtPlot::xTop, QwtPlot::yLeft);
    56. + else _innerTicks [axisId]->setAxes (QwtPlot::xBottom, QwtPlot::yLeft);
    57. + break;
    58. + }
    59. + _innerTicks [axisId]->setAlignment (align);
    60. + _innerTicks [axisId]->setBorderDistance (0); // attach to border
    61. + _innerTicks [axisId]->scaleDraw ()->enableComponent (QwtAbstractScaleDraw::Labels, false);
    62. + }
    63. + if (showMajor) _innerTicks [axisId]->scaleDraw ()->setTickLength (QwtScaleDiv::MajorTick, 8);
    64. + else _innerTicks [axisId]->scaleDraw ()->setTickLength (QwtScaleDiv::MajorTick, 0);
    65. + if (showMinor) _innerTicks [axisId]->scaleDraw ()->setTickLength (QwtScaleDiv::MinorTick, 4);
    66. + else _innerTicks [axisId]->scaleDraw ()->setTickLength (QwtScaleDiv::MinorTick, 0);
    67. +
    68. + _innerTicks [axisId]->setScaleDivFromAxis (true);
    69. + _innerTicks [axisId]->attach (this);
    70. + } else {
    71. + if (_innerTicks [axisId] != NULL) {
    72. + _innerTicks [axisId]->detach ();
    73. + }
    74. + }
    75. +}
    76. +
    77. void Plot::applySettings( const Settings &settings )
    78. {
    79. const int axis = QwtPlot::yLeft;
    80. Index: plot.h
    81. ===================================================================
    82. --- plot.h (revision 1453)
    83. +++ plot.h (working copy)
    84. @@ -4,6 +4,7 @@
    85. #include <qwt_plot.h>
    86.  
    87. class Settings;
    88.  
    89. class Plot: public QwtPlot
    90. {
    91. @@ -14,6 +15,11 @@
    92.  
    93. public Q_SLOTS:
    94. void applySettings( const Settings & );
    95. +
    96. +private:
    97. +
    98. + void InnerTicks(int, bool, bool);
    99. + QwtPlotScaleItem *_innerTicks [4];
    100. };
    101.  
    102. #endif
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,313
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Lining up Inner and Outer Ticks

    An issue with an internal cache of the scale item: fixed in SVN ( trunk + 6.0 branch )

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    bigjoeystud (27th September 2012)

Similar Threads

  1. Lining up of plots in the same horizontal Layout
    By pari in forum Qt Programming
    Replies: 1
    Last Post: 4th June 2012, 12:26
  2. Replies: 1
    Last Post: 26th April 2012, 18:15
  3. Lining up 3 curves of a QwtPlot
    By pihentagy in forum Qwt
    Replies: 2
    Last Post: 18th February 2011, 14:38
  4. Lining up multiple plots
    By joel in forum Qwt
    Replies: 2
    Last Post: 20th June 2008, 00:25
  5. Outer join in QSqlRelationalTableModel
    By Banjo in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2008, 23:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.