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. QGraphicsItem transparency issue
Qt 6.11 is out! See what's new in the release blog

QGraphicsItem transparency issue

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

    I am using a QGraphicsItem to display a QString text within a rectangle in qchart.
    It is done inside paint() of QGraphicsItem. I would like to set QGraphicsItem background transparent. It can be done by setting opacity of the painter in paint(). The code is as follows:

    void MyGraphicsItem::paint( QPainter * painter, const QStyleOptionGraphicsItem* option, QWidget * widget )
    {
    painter->setOpacity(0.0 );
    painter->setBrush( Qt:white );
    painter->drawText( text_rect, str_text );
    }

    if the painter has 0.0 opacity, text will disappear as well. How can I set the background of rectangle text_rect transparent while keeping the text visible?

    A 1 Reply Last reply
    0
    • JoeCFDJ JoeCFD

      I am using a QGraphicsItem to display a QString text within a rectangle in qchart.
      It is done inside paint() of QGraphicsItem. I would like to set QGraphicsItem background transparent. It can be done by setting opacity of the painter in paint(). The code is as follows:

      void MyGraphicsItem::paint( QPainter * painter, const QStyleOptionGraphicsItem* option, QWidget * widget )
      {
      painter->setOpacity(0.0 );
      painter->setBrush( Qt:white );
      painter->drawText( text_rect, str_text );
      }

      if the painter has 0.0 opacity, text will disappear as well. How can I set the background of rectangle text_rect transparent while keeping the text visible?

      A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      @JoeCFD
      Try not setting a brush.

      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