Qt 6.11 is out! See what's new in the release
blog
QTextEdit with QGraphicsDropShadowEffect caret overlap issue
-
I am trying to use a
QTextEditwithQGraphicsDropShadowEffect, 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

#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(); }