Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QwtPlot: how to set the canvas background colour to a semi-transparent?
Forum Updated to NodeBB v4.3 + New Features

QwtPlot: how to set the canvas background colour to a semi-transparent?

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
2 Posts 1 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    agarny
    wrote on last edited by
    #1

    Hi,

    I have a QwtPlot object and I want and need to change its canvas background colour. To that end, I do something like:

    QBrush brush = canvasBackground();
    
    brush.setColor(myColor);
    
    setCanvasBackground(brush);
    

    This works fine with opaque colours, but if I have a semi-transparent colour (e.g. #3a108080), then the effective colour becomes that of its corresponding opaque colour (i.e. #108080). Yet, if I query the canvas background colour, I correctly get #3a108080...!?

    So, what am I doing wrong here?...

    FWIW, I have managed to get things to work as I want by replacing the above code with:

    setStyleSheet(QString("QwtPlotCanvas {"
                          "    background: %1;"
                          "}").arg(myColor.name(QColor::HexArgb)));
    

    Now, although it works fine, I must confess that I would rather avoid having to use style sheets. So, any idea how I achieve the same result using something like my original code?

    Cheers, Alan.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      agarny
      wrote on last edited by
      #2

      Actually, to use style sheets is not right for what I want since I want the semi-transparent colour to be on a white background, while my QwtPlot object has a grey background...

      This means that, in the end, I am doing the following:

      static const QColor White = Qt::white;
      
      QBrush brush = canvasBackground();
      double ratio = myColor.alpha()/256.0;
      
      brush.setColor(QColor((1.0-ratio)*White.red()+ratio*myColor.red(),
                            (1.0-ratio)*White.green()+ratio*myColor.green(),
                            (1.0-ratio)*White.blue()+ratio*myColor.blue()));
      
      setCanvasBackground(brush);
      

      I guess I am happy with that...

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved