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. [SOLVED]How to make the Widget transparent with styleSheet
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to make the Widget transparent with styleSheet

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.6k 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.
  • S Offline
    S Offline
    sirnodin
    wrote on 18 Dec 2012, 05:55 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on 18 Dec 2012, 06:07 last edited by
      #2

      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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sirnodin
        wrote on 18 Dec 2012, 06:25 last edited by
        #3

        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]

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sirnodin
          wrote on 18 Dec 2012, 06:39 last edited by
          #4

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on 18 Dec 2012, 06:46 last edited by
            #5

            [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.

            1 Reply Last reply
            0

            1/5

            18 Dec 2012, 05:55

            • Login

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