Results 1 to 5 of 5

Thread: Stylesheets & printing

  1. #1
    Join Date
    Nov 2006
    Location
    Netherlands
    Posts
    6
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Stylesheets & printing

    Hi all,

    I'm using the Qt4 stylesheets facility to apply a nice looking linear gradient to the background of my plot. This works great in the GUI, but when I print the plot, the stylesheet is ignored.

    Is there an easy way to get this to work or do I need to patch the QwtPlot:: print() methods in Qwt itself?

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

    Default Re: Stylesheets & printing

    When you assign your gradient as background brush for the canvas, printing should paint your gradient too. ( Is there any good reason for using stylesheets for this ? )

    If this is not possible do this:

    Qt Code:
    1. virtual YourPlot::printCanvas(QPainter *painter,
    2. const QRect &boundingRect, const QRect &canvasRect,
    3. const QwtScaleMap maps[axisCnt],
    4. const QwtPlotPrintFilter &filter)
    5. {
    6. // paint your gradient here
    7. ....
    8.  
    9. filter &= ~QwtPlotPrintFilter::PrintBackground;
    10. QwtPlot::printCanvas(painter, ..., filter);
    11. }
    To copy to clipboard, switch view to plain text mode 

    Uwe

  3. #3
    Join Date
    Nov 2006
    Location
    Netherlands
    Posts
    6
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheets & printing

    The stylesheet is mostly for convenience.

    It allows me to store styles like:
    Qt Code:
    1. #my_plot {
    2. background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 white, stop: 0.2 lightgrey, stop: 1 darkgray);
    3. }
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. #my_plot {
    2. background-color: lightsteelblue;
    3. }
    To copy to clipboard, switch view to plain text mode 

    as a simple string in a configuration file.

    I guess the easy way out is to change my config file format a bit and add the gradient code as you suggested.

    Stylesheet support would be a nice feature to have though, you could then easily change the complete look of a plot simply by setting a new stylesheet.

    Thanks,

    Xander.

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

    Default Re: Stylesheets & printing

    I want a gradient background in my plot and have implemented it like you suggested Uwe.
    i.e. I set the gradient to the background brush of the canvas widget, and I've reimplemented printCanvas like this:

    Qt Code:
    1. painter->save();
    2. painter->setBrush(m_canvasBackground);
    3. painter->drawRect(canvasRect);
    4. painter->restore();
    5.  
    6. f.setOptions(filter.options() & ~QwtPlotPrintFilter::PrintBackground);
    7. QwtPlot::printCanvas(painter, boundingRect, canvasRect, maps, f);
    To copy to clipboard, switch view to plain text mode 

    Printing works as expected, however the plot in my application becomes black after this.
    If I re-change the background brush of the canvas palette, all reworks again.

    It looks like a bug in Qwt am I right?

    Moreover, I'd like to know if reimplementing printCanvas is still the better solution? (qwt5.2)

    And the last question: How can I control the print size, the with/height ratio...? I tried to change the paper size in the QPrintDialog but it doesn't work (which seems normal though..).

    Thanks again for your great library!

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

    Default Re: Stylesheets & printing

    Printing works as expected, however the plot in my application becomes black after this.
    I tried your code in the bode example on my Linux box with Qt 4.6.1 - but couldn't see this effect.

    Moreover, I'd like to know if reimplementing printCanvas is still the better solution? (qwt5.2)
    Well, it never was (my answer was about stylesheets only) - but it looks like Qwt 5.x doesn't print the gradient properly. I have not checked why, but Qwt 6.x from SVN trunk prints the gradient out of the box ( although the output is quite heavy for high resolution prints ).

    And the last question: How can I control the print size, the with/height ratio...?
    void QwtPlot::print(QPainter *, const QRect &, ... ) const;

    Uwe

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

    viridis (11th May 2010)

Similar Threads

  1. Printing txt file vs Printing pdf file
    By rmagro in forum Qt Programming
    Replies: 3
    Last Post: 9th July 2012, 15:45
  2. Printing some data
    By cyberboy in forum Qt Programming
    Replies: 1
    Last Post: 28th April 2008, 13:08
  3. Printing problem in windows
    By joseph in forum Qt Programming
    Replies: 6
    Last Post: 12th July 2007, 08:04
  4. Re: Printing in Qt
    By Jimmy2775 in forum Newbie
    Replies: 3
    Last Post: 12th July 2006, 23:00
  5. Replies: 0
    Last Post: 28th June 2006, 20:49

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.