Results 1 to 3 of 3

Thread: removing space in the canvas at the top and bottom

  1. #1
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question removing space in the canvas at the top and bottom

    Thanks for reading.

    I am trying to plot a bar chart and i am not able to totally remove space (at the top and bottom) in the canvas, in a way that only the bar gets shown (when the value is maximum).

    qwtplot_space.png

    How do i remove the black portions at the top and bottom of the canvas?


    My code as follows:

    I promoted a QWidget to QwtPlot (ui->widget)

    Qt Code:
    1. //contentsmagin reduces a pixel line or two but doesnot totally remove everything
    2. ui->widget->canvas()->setContentsMargins(0,0,0,0);
    3.  
    4. QwtPlotBarChart* device_cri_bar_plot = new QwtPlotBarChart("Device");
    5. device_cri_bar_plot->attach(ui->widget);
    6.  
    7. // removes the side (left & right) portions and the axes
    8. ui->widget->setAxisMaxMinor(QwtPlot::yLeft,0);
    9. ui->widget->setAxisMaxMajor(QwtPlot::xBottom,0);
    10. ui->widget->setAxisMaxMinor(QwtPlot::xBottom,0);
    11. ui->widget->setAxisAutoScale(QwtPlot::yLeft,true);
    12. ui->widget->setAxisAutoScale(QwtPlot::xBottom,false);
    13. ui->widget->setAxisScale(QwtPlot::yLeft,0,1);
    14. ui->widget->setAxisScale(QwtPlot::xBottom,-0.25,0.25);
    15. ui->widget->axisWidget( QwtPlot::yLeft )->setMargin( 0 );
    16. ui->widget->axisWidget( QwtPlot::xBottom )->setMargin( 0 );
    17. ui->widget->axisWidget( QwtPlot::xTop )->setMargin( 0 );
    18. ui->widget->enableAxis(QwtPlot::xBottom, false);
    19.  
    20.  
    21. ui->widget->setCanvasBackground(* new QBrush(Qt::black));
    22.  
    23.  
    24. //plot a green bar
    25. QwtColumnSymbol *ptr_to_bar_in_barchart = new QwtColumnSymbol( QwtColumnSymbol::Box );
    26. ptr_to_bar_in_barchart->setLineWidth( 0 );
    27. ptr_to_bar_in_barchart->setFrameStyle( QwtColumnSymbol::NoFrame );
    28. QColor barColor( 0,150,0 );
    29. QVector<QPointF> barpoints;
    30. barpoints<< QPointF(0,1) ;
    31. ptr_to_bar_in_barchart->setPalette( barColor );
    32. device_cri_bar_plot->setSymbol(ptr_to_bar_in_barchart);
    33. device_cri_bar_plot->setSamples(barpoints);
    To copy to clipboard, switch view to plain text mode 


    any help would be most helpful.

  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: removing space in the canvas at the top and bottom

    Qt Code:
    1. plot->plotLayout()->setAlignCanvasToScales( true );
    To copy to clipboard, switch view to plain text mode 

    Uwe

  3. #3
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Thumbs up Re: removing space in the canvas at the top and bottom

    Uwe, thanks a lot!

Similar Threads

  1. QTableView empty space or too little space.
    By davemar in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2009, 16:00
  2. Why QStatusBar do not at the bottom?
    By FinderCheng in forum Qt Programming
    Replies: 5
    Last Post: 29th September 2009, 08:26
  3. Replies: 1
    Last Post: 26th July 2009, 15:08
  4. Replies: 7
    Last Post: 15th November 2007, 17:19
  5. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2006, 23:11

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.