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 with QGraphicsDropShadowEffect caret overlap issue
Qt 6.11 is out! See what's new in the release blog

QTextEdit with QGraphicsDropShadowEffect caret overlap issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 191 Views
  • 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.
  • J Offline
    J Offline
    jonathan-f-silva
    wrote on last edited by
    #1

    I am trying to use a QTextEdit with QGraphicsDropShadowEffect, but the caret is being overlapped by the shadow, maybe am I missing something?

    I am using:

    • Windows 11 24H2 26100.4349
    • Qt Creator 17.0.0
    • Qt 6.9.1
    • Qt and Qt Creator installed via Qt Online Installer

    qttextedit bug.gif

    #include <QApplication>
    #include <QWidget>
    #include <QTextEdit>
    #include <QVBoxLayout>
    #include <QHBoxLayout>
    #include <QPalette>
    #include <QGraphicsEffect>
    #include <QCheckBox>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        // ----- Main window ------------------------------------------------------
        QWidget mainWindow;
        mainWindow.setFixedSize(300, 300);
        mainWindow.setWindowTitle("QTextEdit caret bug");
    
        QPalette pal = mainWindow.palette();
        pal.setColor(QPalette::Window, Qt::white);
        mainWindow.setAutoFillBackground(true);
        mainWindow.setPalette(pal);
    
        // ----- QTextEdit --------------------------------------------------------
        QTextEdit *textEdit = new QTextEdit;
        textEdit->setFixedSize(200, 200);
        textEdit->setText("Dark‑yellow bold 20 px text on transparent background");
        textEdit->setFrameStyle(QFrame::NoFrame);
    
        textEdit->setStyleSheet(
            "QTextEdit {"
            "background: transparent;"
            "color: #B8860B;"
            "font-weight: bold;"
            "font-size: 20px;"
            "}"
            );
    
        // ----- Drop shadow effect -----------------------------------------------
        auto *shadowEffect = new QGraphicsDropShadowEffect(&mainWindow);
        shadowEffect->setBlurRadius(10.0);
        shadowEffect->setOffset(3, 3);
        shadowEffect->setColor(QColor(0, 0, 0, 128));
        textEdit->setGraphicsEffect(shadowEffect);
    
        // ----- Checkbox to toggle shadow ----------------------------------------
        auto *shadowCheckBox = new QCheckBox("Enable drop shadow");
        shadowCheckBox->setStyleSheet("QCheckBox { color: black; }");
        shadowCheckBox->setChecked(true);
        QObject::connect(shadowCheckBox, &QCheckBox::toggled,
                         shadowEffect,      &QGraphicsEffect::setEnabled);
    
        // ----- Layout -----------------------------------------------------------
        auto *vLayout = new QVBoxLayout(&mainWindow);
        vLayout->addStretch();
    
        auto *hText = new QHBoxLayout;
        hText->addStretch();
        hText->addWidget(textEdit);
        hText->addStretch();
        vLayout->addLayout(hText);
    
        auto *hCheck = new QHBoxLayout;
        hCheck->addStretch();
        hCheck->addWidget(shadowCheckBox);
        hCheck->addStretch();
        vLayout->addLayout(hCheck);
    
        vLayout->addStretch();
    
        mainWindow.show();
        return app.exec();
    }
    
    
    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