Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't set opacity to QLinearGradient
Forum Updated to NodeBB v4.3 + New Features

Can't set opacity to QLinearGradient

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 893 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.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by
    #1

    Hi,

    I'm trying to set opacity to QLinearGradient that I use in QWT plot and seems to me that it doesn't work:

        QLinearGradient linearGrad(QPointF(0, 0), QPointF(1, 0));
        linearGrad.setCoordinateMode(QGradient::ObjectMode);
        linearGrad.setColorAt(0, Qt::yellow);
        linearGrad.setColorAt(0.5, Qt::red);
        linearGrad.setColorAt(1, Qt::cyan);
    
        QGraphicsOpacityEffect* opacity = new QGraphicsOpacityEffect;
        opacity->setOpacity(0);
        opacity->setOpacityMask(linearGrad);
    

    I get the picture below but it shold be fully transparent, isn' it?
    d970ae19-1ecd-4a7d-9321-699e22a4733f-image.png

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Please_Help_me_D said in Can't set opacity to QLinearGradient:

      QGraphicsOpacityEffect

      Hi
      QGraphicsOpacityEffect is to apply to widgets.
      Your code does not seems to set it on anything ?

      Please_Help_me_DP 1 Reply Last reply
      1
      • mrjjM mrjj

        @Please_Help_me_D said in Can't set opacity to QLinearGradient:

        QGraphicsOpacityEffect

        Hi
        QGraphicsOpacityEffect is to apply to widgets.
        Your code does not seems to set it on anything ?

        Please_Help_me_DP Offline
        Please_Help_me_DP Offline
        Please_Help_me_D
        wrote on last edited by
        #3

        @mrjj thank you for answer
        I'm sorry, I forgot to add lines where I apply QLinearGradient to the curve that was generated with QwtPlotCurve:

        QwtPlotCurve *curve = new QwtPlotCurve();
        
        QLinearGradient linearGrad(QPointF(0, 0), QPointF(1, 0));
        linearGrad.setCoordinateMode(QGradient::ObjectMode);
        linearGrad.setColorAt(0, Qt::yellow);
        linearGrad.setColorAt(0.5, Qt::red);
        linearGrad.setColorAt(1, Qt::cyan);  
        
        QGraphicsOpacityEffect* opacity = new QGraphicsOpacityEffect;
        opacity->setOpacity(0);
        opacity->setOpacityMask(linearGrad);
        
        curve->setBrush(linearGrad);
        

        So the filled area is the area between the curve and some baseline located at y=10000

        I found a way to set opacity of each color like:

            QColor green70 = Qt::green;
            green70.setAlphaF(0.7); // here we set the opacity (or more likely transparency)
            linearGrad.setColorAt(1, green70);
        

        That works but if I want to change the opacity I would need to change alpha of every color in loop. Actually that is not so bad but I'm trying to implement linear colorbar where colors are linearly changeable and they are set by some value (not by a name like red or green).

        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