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. [Qt 4.8] How to use QGraphicsDropShadowEffect while defining a QStyle ?
Forum Updated to NodeBB v4.3 + New Features

[Qt 4.8] How to use QGraphicsDropShadowEffect while defining a QStyle ?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.5k 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.
  • E Offline
    E Offline
    Essoussi
    wrote on last edited by
    #1

    Hello,

    I am redifining a customized Style for my desktop application in which I would like to draw buttons with shadow effects.
    To do so, I tried to overload the drawPrimitive method in my class which is an extension of QMotifStyle (see the following code).

    @void MyStyle_c::drawPrimitive(PrimitiveElement element,
    const QStyleOption *option,
    QPainter *painter,
    const QWidget *widget) const
    {

      int x, y, width, height;
     option->rect.getRect(&x, &y, &width, &height);
    
     switch (element) {
    

    ....
    case PE_PanelButtonCommand:
    {
    .......
    painter->setRenderHint(QPainter::Antialiasing, true);
    QGraphicsRectItem * item = new QGraphicsRectItem(x,y,width,height);

            QGraphicsDropShadowEffect * effect = new QGraphicsDropShadowEffect ;
             effect->setBlurRadius(5);   
             effect->setColor(Qt::blue);
             item->setGraphicsEffect(effect); /* NO EFFECT !*/ 
             painter->drawPath(item->shape());
    
         }
         break;
    

    ....

     default:
         QMotifStyle::drawPrimitive(element, option, painter, widget);
     }
    

    }
    @

    It's drawn properly but without any effect. Could you please tell me why ? What am I doing wrong ?

    Thanks you a lot
    Habib

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      that's not how it works. You set the graphics effect on the item but in the next step you are drawing only the shape (QPainterPath)...
      You should rather set it outside of the style where you actually use the item/widget. The effect is meant to be used as an addition to the painting of the item.

      If you want to do it in the style you would have to do it yourself with QPainter's methods and gradients for example. But this may be tricky since you may get performance issues if you don't optimize the code.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      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