Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-136696

Surprising behavior of QTextCharFormat::setForeground(Qt::NoBrush)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 6.2.4, 6.10
    • GUI: Text handling
    • None
    • Ubuntu 24.04 LTS

      1. In a QTextLayout, assign a pen for the text's outline and Qt::NoBrush for the text's foreground:
            QTextLayout textLayout("Qt");
            QTextLayout::FormatRange range;
            range.start = 0;
            range.length = 2;
            range.format.setFont(f);
            range.format.setTextOutline(pen);
            range.format.setForeground(Qt::NoBrush);
            textLayout.setFormats(QList<QTextLayout::FormatRange>{range});
        
      2. Draw this using a QPainter:
        textLayout.draw(&p, QPoint(0, 200));
        

        Expected: The drawn characters will not be filled, i.e. inside the outline, they will be transparent:

        Actual: The drawn characters are filled with the color of the outline's pen:

      I attached a small project to reproduce the issue. It also draws a rectangle for comparison.

      Workaround: Setting the foreground to Qt::transparent draws the expected shape.

        1. actual.png
          7 kB
          Robert Löhning
        2. CMakeLists.txt
          0.6 kB
          Robert Löhning
        3. expected.png
          11 kB
          Robert Löhning
        4. main.cpp
          1 kB
          Robert Löhning
        5. text_invisible.svg
          0.6 kB
          Robert Löhning
        For Gerrit Dashboard: QTBUG-136696
        # Subject Branch Project Status CR V

            esabraha Eskil Abrahamsen Blomfeldt
            rlohning Robert Löhning
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There is 1 open Gerrit change