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. QTextEdit transparency in QGraphicsView
Forum Updated to NodeBB v4.3 + New Features

QTextEdit transparency in QGraphicsView

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 3.6k Views 3 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.
  • D Offline
    D Offline
    David Stephan
    wrote on last edited by
    #1

    I've been trying to make a transparent QTextEdit in a QGraphicsView. However, the background of the QTextEdit is always white. After lots of trial and error I found that text->setFrameShape(QFrame::NoFrame) gets rid of the white background.

    1. Why is QFrame::NoFrame needed?
    2. Why is the coloring different (see image)?

    QPlainTextEdit exhibits the same issue.
    QLabel and QLineEdit don't have the issue

    Environment

    Qt 5.9.1
    Windows 10
    Visual Studio 2015

    Example

    0_1502825201075_transparency.png

    QMainWindow w;
    w.resize(400, 100);
    w.setStyleSheet(".QMainWindow{background : black;}");
    
    QWidget bar(&w);
    bar.setGeometry(0, 0, 400, 40);
    bar.setStyleSheet("background-color : rgb(0,255,0);");
    
    QTextEdit text1(&w);
    text1.setText("Working");
    text1.setStyleSheet("background-color : rgba(255,0,0,50%); color : white;");
    text1.setGeometry(0, 0, 80, 80);
    
    QGraphicsScene scene;
    QGraphicsView view(&w);
    view.setGeometry(100, 0, 300, 100);
    view.setStyleSheet(".QGraphicsView{background : transparent;}");
    
    QTextEdit text2;
    text2.setText("Broken");
    text2.setStyleSheet("background-color : rgba(255,0,0,50%); color : black;");
    text2.setGeometry(0, 0, 80, 80);
    scene.addWidget(&text2);
    
    QTextEdit text3;
    text3.setText("Almost Working");
    text3.setStyleSheet("background-color : rgba(255,0,0,50%); color : white;");
    text3.setGeometry(100, 0, 80, 80);
    text3.setFrameShape(QFrame::NoFrame);
    scene.addWidget(&text3);
    
    QFrame frame;
    frame.setStyleSheet("background-color : rgba(255,0,0,50%);");
    frame.setGeometry(200, 0, 80, 80);
    scene.addWidget(&frame);
    
    view.setScene(&scene);
    
    w.show();
    
    raven-worxR 1 Reply Last reply
    0
    • D David Stephan

      I've been trying to make a transparent QTextEdit in a QGraphicsView. However, the background of the QTextEdit is always white. After lots of trial and error I found that text->setFrameShape(QFrame::NoFrame) gets rid of the white background.

      1. Why is QFrame::NoFrame needed?
      2. Why is the coloring different (see image)?

      QPlainTextEdit exhibits the same issue.
      QLabel and QLineEdit don't have the issue

      Environment

      Qt 5.9.1
      Windows 10
      Visual Studio 2015

      Example

      0_1502825201075_transparency.png

      QMainWindow w;
      w.resize(400, 100);
      w.setStyleSheet(".QMainWindow{background : black;}");
      
      QWidget bar(&w);
      bar.setGeometry(0, 0, 400, 40);
      bar.setStyleSheet("background-color : rgb(0,255,0);");
      
      QTextEdit text1(&w);
      text1.setText("Working");
      text1.setStyleSheet("background-color : rgba(255,0,0,50%); color : white;");
      text1.setGeometry(0, 0, 80, 80);
      
      QGraphicsScene scene;
      QGraphicsView view(&w);
      view.setGeometry(100, 0, 300, 100);
      view.setStyleSheet(".QGraphicsView{background : transparent;}");
      
      QTextEdit text2;
      text2.setText("Broken");
      text2.setStyleSheet("background-color : rgba(255,0,0,50%); color : black;");
      text2.setGeometry(0, 0, 80, 80);
      scene.addWidget(&text2);
      
      QTextEdit text3;
      text3.setText("Almost Working");
      text3.setStyleSheet("background-color : rgba(255,0,0,50%); color : white;");
      text3.setGeometry(100, 0, 80, 80);
      text3.setFrameShape(QFrame::NoFrame);
      scene.addWidget(&text3);
      
      QFrame frame;
      frame.setStyleSheet("background-color : rgba(255,0,0,50%);");
      frame.setGeometry(200, 0, 80, 80);
      scene.addWidget(&frame);
      
      view.setScene(&scene);
      
      w.show();
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @David-Stephan
      i also encountered this a few times and debugging showed that this relies somewhere in the depths of QStyle imeplementations. Sometimes you need to style border and background together. So i bet it would also work when you add border:0; to your stylesheets.

      --- 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
      3
      • D Offline
        D Offline
        David Stephan
        wrote on last edited by
        #3

        Wow that also works. Thanks

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          Just wondering...why not QGraphicsTextItem? Wrapping a QWidget into a QGraphicsScene is always costly and complicated.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            David Stephan
            wrote on last edited by
            #5

            @Asperamanca
            I wanted QTextEdit's scrollbar.

            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