Results 1 to 4 of 4

Thread: Grid Minor Major and gap before the data

  1. #1
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Grid Minor Major and gap before the data

    Hi,
    This is the code in the constructor :
    Qt Code:
    1. PlotWidget::PlotWidget(QWidget * parent, double * _ySession,
    2. QString name, int rate, int numVis, int numSess)
    3. : QwtPlot(parent) {
    4. // data stuff....
    5.  
    6. QwtPainter::setDeviceClipping(false);
    7. canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, true);
    8. canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, true);
    9. //canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
    10. canvas()->setFrameStyle(QFrame::Box | QFrame::Plain);
    11. canvas()->setLineWidth(1);
    12. canvas()->setMidLineWidth(0);
    13. setCanvasBackground(QColor(Qt::white));
    14. enableAxis(QwtPlot::xBottom, false);
    15. enableAxis(QwtPlot::yLeft, false);
    16. setMargin(0);
    17.  
    18. setAxisScale(QwtPlot::xBottom,0.0, sizeLoop);
    19. setAxisScale(QwtPlot::yLeft,1500, 3000, 0 );
    20.  
    21. setAxisMaxMajor(QwtPlot::yLeft, 8);
    22. setAxisMaxMinor(QwtPlot::yLeft, 5);
    23.  
    24. QwtValueList vlist[3];
    25. for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13*5))
    26. vlist[0] << i;
    27. for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13))
    28. vlist[1] << i;
    29. for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13))
    30. vlist[2] << i;
    31. QwtScaleDiv scdiv(0, sizeLoop, vlist);
    32. setAxisScaleDiv(QwtPlot::xBottom, scdiv);
    33.  
    34. // for inside margin (I think)
    35. axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating);
    36. axisScaleEngine(QwtPlot::xTop)->setAttributes(QwtScaleEngine::Floating);
    37. axisScaleEngine(QwtPlot::yLeft)->setAttributes(QwtScaleEngine::Floating);
    38. axisScaleEngine(QwtPlot::yRight)->setAttributes(QwtScaleEngine::Floating);
    39.  
    40. curve = new QwtPlotCurve(name);
    41. //curve->setRenderHint(QwtPlotItem::RenderAntialiased);
    42. pen->setWidthF(penWidth + penWidthDiff);
    43. curve->setPen(*pen);
    44. curve->attach(this);
    45. curve->setRawData(xLoop, yLoop, sizeLoop);
    46.  
    47. grid = new QwtPlotGrid;
    48. grid->enableXMin(true);
    49. grid->enableYMin(true);
    50. gridMinPen = new QPen(QColor(255, 230, 230), 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    51. gridMajPen = new QPen(QColor(255, 200, 200), 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    52. grid->setMajPen(*gridMajPen);
    53. grid->setMinPen(*gridMinPen);
    54. grid->attach(this);
    55. }
    To copy to clipboard, switch view to plain text mode 

    And the code in the derived print filter :
    Qt Code:
    1. QColor MyQwtPlotPrintFilter::color(const QColor &c, Item item) const {
    2. switch(item){
    3. case MajorGrid:
    4. return Qt::blue;
    5. case MinorGrid:
    6. return Qt::green;
    7. default:;
    8. }
    9. return c;
    10. }
    To copy to clipboard, switch view to plain text mode 

    I got the exported pdf as attached "export.pdf". But I want to get "expected.png".
    I added the colors to see the major and minor grids.

    Now, the problem is :
    1) I cannot see the minor grids at x axis.
    2) I dont want a gap between the starting data and plot edge.

    For 2'nd I found :
    axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating);
    but I couldn't realize what the QwtScaleEngine::Floating means (and other Attribute's)

    Thanks for help.


    Hüseyin
    Attached Images Attached Images
    Attached Files Attached Files

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

    Default Re: Grid Minor Major and gap before the data

    Quote Originally Posted by huseyinkozan View Post
    Now, the problem is :
    1) I cannot see the minor grids at x axis.
    2) I dont want a gap between the starting data and plot edge.
    1) Are there any minor ticks in your bottom scale ?
    2) plot->plotLayout()->setAlignCanvasToScales(true);

    Uwe

  3. #3
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Grid Minor Major and gap before the data

    Quote Originally Posted by Uwe View Post
    1) Are there any minor ticks in your bottom scale ?
    2) plot->plotLayout()->setAlignCanvasToScales(true);

    Uwe
    1) I found the QwtValueList model here : http://thread.gmane.org/gmane.comp.g...t.general/1425
    Does this not assign the minor, medium and major ticks ?

    2) I have added the code and plotLayout()->setCanvasMargin(...) it works.

    Thanks.


    Hüseyin

    Note: I am using 5.1.2-svn, Qt 4.5 with msvc addin. And the code is here:
    Qt Code:
    1. PlotWidget::PlotWidget(QWidget * parent, double * _ySession,
    2. QString name, int rate, int numVis, int numSess)
    3. : QwtPlot(parent)
    4. {
    5. setAutoReplot(false);
    6. sampRate = rate;
    7. plotName = name;
    8. sizeLoop = numVis;
    9. sizeVisible = numVis;
    10. sizeSession = numSess;
    11. scrollModeOn = false;
    12. clearPlot = false;
    13. indexLoop = 0;
    14. sessionScrollIndex = 0;
    15. pageDiv = 50;
    16. xLoop = new double[sizeLoop];
    17. yLoop = new double[sizeLoop];
    18. ySession = _ySession;
    19. pen = new QPen(Qt::black);
    20. penWidth = 1.0;
    21. penWidthDiff = 0.5;
    22. gridMinPenWidth = 1.0;
    23. gridMajPenWidth = 1.0;
    24. for (int i = 0; i < sizeLoop; i++){
    25. xLoop[i] = i;
    26. yLoop[i] = 0.0;
    27. }
    28.  
    29. QwtPainter::setDeviceClipping(false);
    30. canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, true);
    31. canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, true);
    32. //canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
    33. canvas()->setFrameStyle(QFrame::Box | QFrame::Plain);
    34. canvas()->setLineWidth(1);
    35. canvas()->setMidLineWidth(0);
    36. setCanvasBackground(QColor(Qt::white));
    37. enableAxis(QwtPlot::xBottom, false);
    38. enableAxis(QwtPlot::yLeft, false);
    39. setMargin(0);
    40.  
    41. setAxisScale(QwtPlot::xBottom,0.0, sizeLoop);
    42. setAxisScale(QwtPlot::yLeft,1500, 3000, 0 );
    43.  
    44. setAxisMaxMajor(QwtPlot::yLeft, 8);
    45. setAxisMaxMinor(QwtPlot::yLeft, 5);
    46.  
    47. QwtValueList vlist[3];
    48. for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13*5))
    49. vlist[0] << i;
    50. for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13))
    51. vlist[1] << i;
    52. for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13))
    53. vlist[2] << i;
    54. QwtScaleDiv scdiv(0, sizeLoop, vlist);
    55. scdiv.setTicks(QwtScaleDiv::MinorTick, vlist[1]);
    56. setAxisScaleDiv(QwtPlot::xBottom, scdiv);
    57.  
    58. // for inside margin
    59. plotLayout()->setAlignCanvasToScales(true);
    60. plotLayout()->setCanvasMargin(0,QwtPlot::xBottom);
    61. plotLayout()->setCanvasMargin(0,QwtPlot::xTop);
    62. plotLayout()->setCanvasMargin(0,QwtPlot::yLeft);
    63. plotLayout()->setCanvasMargin(0,QwtPlot::yRight);
    64.  
    65. curve = new QwtPlotCurve(plotName);
    66. pen->setWidthF(penWidth + penWidthDiff);
    67. curve->setPen(*pen);
    68. curve->attach(this);
    69. curve->setRawData(xLoop, yLoop, sizeLoop);
    70.  
    71. grid = new QwtPlotGrid;
    72. grid->enableXMin(true);
    73. grid->enableYMin(true);
    74. gridMinPen = new QPen(QColor(255, 230, 230), 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    75. gridMajPen = new QPen(QColor(255, 200, 200), 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    76. grid->setMajPen(*gridMajPen);
    77. grid->setMinPen(*gridMinPen);
    78. grid->attach(this);
    79.  
    80. labelMarker = new QwtPlotMarker;
    81. labelMarker->setValue(QwtDoublePoint(50, 2900));
    82. QwtText text(plotName);
    83. text.setFont(QFont("Verdana", 10, QFont::Bold));
    84. text.setColor(QColor(180,180,180));
    85. text.setRenderFlags(Qt::AlignLeft);
    86. labelMarker->setLabel(text);
    87. labelMarker->attach(this);
    88. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2008
    Posts
    26
    Thanks
    5
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Grid Minor Major and gap before the data

    Hi,

    I don't want any spacing between the scale backbone and the canvas (plotting area). Thus, the backbones of the left and bottom axes should be "connected". I tried the following without success (there is a 1 or 2 pixels gap):

    Qt Code:
    1. plotLayout()->setAlignCanvasToScales(true);
    2. plotLayout()->setCanvasMargin(0, QwtPlot::xBottom);
    3. plotLayout()->setCanvasMargin(0, QwtPlot::xTop);
    4. plotLayout()->setCanvasMargin(0, QwtPlot::yLeft);
    5. plotLayout()->setCanvasMargin(0, QwtPlot::yRight);
    6. plotLayout()->setSpacing(0);
    7. plotLayout()->setMargin(0);
    To copy to clipboard, switch view to plain text mode 

    Any hints?

Similar Threads

  1. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 23:46
  2. Replies: 7
    Last Post: 29th August 2008, 11:24
  3. Replies: 4
    Last Post: 19th October 2007, 20:47
  4. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 13:14
  5. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 13:53

Tags for this Thread

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.