[SOLVED]How to make the Widget transparent with styleSheet



  • i konw other ways to make the widget transparent or having strange shape, but i wonder how to make it with styleSheet?

    How to make the Widget transparent with styleSheet?
    whent i write:
    @
    background-color:transparent
    @
    the backgournd of the widget turns out to be in black color.



  • Is it a QWidget or your custom widget that subclasses QWidget ? If you are creating your own custom widget that inherits from QWidget, you need to override the paintEvent() for your custom widget to make the stylesheet work.

    eg :-

    @void CustomWidget::paintEvent(QPaintEvent *event)
    {
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    }@

    you can have a look at "this":http://qt-project.org/wiki/How_to_Change_the_Background_Color_of_QWidget



  • Well, Thanks.

    But I already know that, and in fact what u said was just what I did.

    My problem is, i tried to give the Widget a color "transparent", but it won't work as what i think "transparent" is.

    it turns out that the Widget got a black color rather than a "transparent" one. How to fix it?

    [quote author="Sam" date="1355810845"]Is it a QWidget or your custom widget that subclasses QWidget ? If you are creating your own custom widget that inherits from QWidget, you need to override the paintEvent() for your custom widget to make the stylesheet work.

    eg :-

    @void CustomWidget::paintEvent(QPaintEvent *event)
    {
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    }@

    you can have a look at "this":http://qt-project.org/wiki/How_to_Change_the_Background_Color_of_QWidget[/quote]



  • Well, i add a
    @
    setAttribute(Qt::WA_TranslucentBackground, true);
    @
    int the cpp file. it seems to work fine....
    Maybe my problem is solved.



  • [quote author="sirnodin" date="1355812795"]Well, i add a
    @
    setAttribute(Qt::WA_TranslucentBackground, true);
    @
    int the cpp file. it seems to work fine....
    Maybe my problem is solved.[/quote]

    Yeah i forgot to add that one. For reference there are some other topics "here":http://doc.qt.digia.com/qq/qq16-background.html and "here":http://qt-project.org/forums/viewthread/1107

    Regards
    Soumitra.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.