diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 4518d8c736..5d6af42921 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -1392,6 +1392,7 @@ void QRenderRule::drawRule(QPainter *p, const QRect& rect)
 // *shudder* , *horror*, *whoa* <-- what you might feel when you see the functions below
 void QRenderRule::configurePalette(QPalette *p, QPalette::ColorRole fr, QPalette::ColorRole br)
 {
+    qDebug() << "QRenderRule::configurePalette" << fr << br;
     if (bg && bg->brush.style() != Qt::NoBrush) {
         if (br != QPalette::NoRole)
             p->setBrush(br, bg->brush);
@@ -1423,25 +1424,31 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorRole fr, QPalette
 
 void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const QWidget *w, bool embedded)
 {
+    qDebug() << __FUNCTION__ << w << cg;
     if (bg && bg->brush.style() != Qt::NoBrush) {
         p->setBrush(cg, QPalette::Base, bg->brush); // for windows, windowxp
         p->setBrush(cg, QPalette::Button, bg->brush); // for plastique
         p->setBrush(cg, w->backgroundRole(), bg->brush);
+        qDebug() << __FUNCTION__ << w << '1' << bg->brush.color().name();
         p->setBrush(cg, QPalette::Window, bg->brush);
     }
 
     if (embedded) {
         /* For embedded widgets (ComboBox, SpinBox and ScrollArea) we want the embedded widget
          * to be transparent when we have a transparent background or border image */
+
         if ((hasBackground() && background()->isTransparent())
-            || (hasBorder() && border()->hasBorderImage() && !border()->borderImage()->pixmap.isNull()))
+                || (hasBorder() && border()->hasBorderImage() && !border()->borderImage()->pixmap.isNull())) {
+            qDebug() << __FUNCTION__ << w << '2';
             p->setBrush(cg, w->backgroundRole(), Qt::NoBrush);
+        }
     }
 
     if (!hasPalette())
         return;
 
     if (pal->foreground.style() != Qt::NoBrush) {
+        qDebug() << __FUNCTION__ << w << "foreground" << pal->foreground.color().name();
         p->setBrush(cg, QPalette::ButtonText, pal->foreground);
         p->setBrush(cg, w->foregroundRole(), pal->foreground);
         p->setBrush(cg, QPalette::WindowText, pal->foreground);
@@ -6088,6 +6095,7 @@ void QStyleSheetStyle::clearWidgetFont(QWidget* w) const
 // Returns \c true if there is a new palette in pal.
 bool QStyleSheetStyle::styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal)
 {
+    qDebug() << __FUNCTION__ << w;
     if (!w || !opt || !pal)
         return false;
 
diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp
index 598d173144..2e09bef551 100644
--- a/src/widgets/widgets/qabstractscrollarea.cpp
+++ b/src/widgets/widgets/qabstractscrollarea.cpp
@@ -1263,6 +1263,7 @@ void QAbstractScrollArea::resizeEvent(QResizeEvent *)
 */
 void QAbstractScrollArea::paintEvent(QPaintEvent*)
 {
+    qDebug() << "QAbstractScrollArea::paintEvent" << this;
 }
 
 /*!
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 86c7d35dbc..2549e47083 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -1859,6 +1859,7 @@ QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property, QVariant arg
 
 void QLineEdit::focusInEvent(QFocusEvent *e)
 {
+    qDebug() << __FUNCTION__ << this << e;
     Q_D(QLineEdit);
     if (e->reason() == Qt::TabFocusReason ||
          e->reason() == Qt::BacktabFocusReason  ||
@@ -1900,6 +1901,7 @@ void QLineEdit::focusInEvent(QFocusEvent *e)
 
 void QLineEdit::focusOutEvent(QFocusEvent *e)
 {
+    qDebug() << __FUNCTION__ << this << e;
     Q_D(QLineEdit);
     if (d->control->passwordEchoEditing()) {
         // Reset the echomode back to PasswordEchoOnEdit when the widget loses
@@ -1939,6 +1941,7 @@ void QLineEdit::focusOutEvent(QFocusEvent *e)
 void QLineEdit::paintEvent(QPaintEvent *)
 {
     Q_D(QLineEdit);
+    qDebug() << "QLineEdit::paintEvent" << this;
     QPainter p(this);
     QPalette pal = palette();
 
@@ -2031,6 +2034,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
         cssStyle->styleSheetPalette(this, &panel, &pal);
     }
 #endif
+    qDebug() << "QLineEdit::paintEvent" << pal.text().color().name();
     p.setPen(pal.text().color());
 
     int flags = QWidgetLineControl::DrawText;
diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp
index 0b5e69b6c3..23bf371a67 100644
--- a/src/widgets/widgets/qplaintextedit.cpp
+++ b/src/widgets/widgets/qplaintextedit.cpp
@@ -778,7 +778,7 @@ void QPlainTextEditPrivate::init(const QString &txt)
     QAbstractTextDocumentLayout *layout = new QPlainTextDocumentLayout(doc);
     doc->setDocumentLayout(layout);
     control->setDocument(doc);
-
+    qDebug() << __FUNCTION__ << q;
     control->setPalette(q->palette());
 
     QObject::connect(vbar, SIGNAL(actionTriggered(int)), q, SLOT(_q_verticalScrollbarActionTriggered(int)));
@@ -1925,6 +1925,7 @@ static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, const
 void QPlainTextEdit::paintEvent(QPaintEvent *e)
 {
     Q_D(QPlainTextEdit);
+    qDebug() << "QPlainTextEdit::paintEvent" << this;
     QPainter painter(viewport());
     Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()));
 
@@ -1963,6 +1964,8 @@ void QPlainTextEdit::paintEvent(QPaintEvent *e)
         QRectF r = blockBoundingRect(block).translated(offset);
         QTextLayout *layout = block.layout();
 
+        qDebug() << "QPlainTextEdit::paintEvent" <<  block.text();
+
         if (!block.isVisible()) {
             offset.ry() += r.height();
             block = block.next();
@@ -1974,6 +1977,7 @@ void QPlainTextEdit::paintEvent(QPaintEvent *e)
             QTextBlockFormat blockFormat = block.blockFormat();
 
             QBrush bg = blockFormat.background();
+            qDebug() << block.text() << "bg=" << bg.color().name();
             if (bg != Qt::NoBrush) {
                 QRectF contentsRect = r;
                 contentsRect.setWidth(qMax(r.width(), maximumWidth));
@@ -2051,6 +2055,7 @@ void QPlainTextEdit::paintEvent(QPaintEvent *e)
 
     if (backgroundVisible() && !block.isValid() && offset.y() <= er.bottom()
         && (centerOnScroll() || verticalScrollBar()->maximum() == verticalScrollBar()->minimum())) {
+         qDebug() << __FUNCTION__ << "fill" << palette().background().color().name();
         painter.fillRect(QRect(QPoint((int)er.left(), (int)offset.y()), er.bottomRight()), palette().background());
     }
 }
@@ -2287,6 +2292,7 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a
 */
 void QPlainTextEdit::focusInEvent(QFocusEvent *e)
 {
+    qDebug() << __FUNCTION__ << this << e;
     Q_D(QPlainTextEdit);
     if (e->reason() == Qt::MouseFocusReason) {
         d->clickCausedFocus = 1;
@@ -2299,6 +2305,7 @@ void QPlainTextEdit::focusInEvent(QFocusEvent *e)
 */
 void QPlainTextEdit::focusOutEvent(QFocusEvent *e)
 {
+    qDebug() << __FUNCTION__ << this << e;
     Q_D(QPlainTextEdit);
     QAbstractScrollArea::focusOutEvent(e);
     d->sendControlEvent(e);
@@ -2331,6 +2338,7 @@ void QPlainTextEdit::changeEvent(QEvent *e)
         e->setAccepted(isEnabled());
         d->sendControlEvent(e);
     } else if (e->type() == QEvent::PaletteChange) {
+        qDebug() << __FUNCTION__ << this << e;
         d->control->setPalette(palette());
     } else if (e->type() == QEvent::LayoutDirectionChange) {
         d->sendControlEvent(e);
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp
index ab636660d7..aab992da36 100644
--- a/src/widgets/widgets/qtextedit.cpp
+++ b/src/widgets/widgets/qtextedit.cpp
@@ -143,6 +143,7 @@ void QTextEditPrivate::createAutoBulletList()
 void QTextEditPrivate::init(const QString &html)
 {
     Q_Q(QTextEdit);
+    qDebug() << __FUNCTION__ << q;
     control = new QTextEditControl(q);
     control->setPalette(q->palette());
 
@@ -1787,6 +1788,7 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume
 */
 void QTextEdit::focusInEvent(QFocusEvent *e)
 {
+    qDebug() << __FUNCTION__ << this << e;
     Q_D(QTextEdit);
     if (e->reason() == Qt::MouseFocusReason) {
         d->clickCausedFocus = 1;
@@ -1800,6 +1802,7 @@ void QTextEdit::focusInEvent(QFocusEvent *e)
 void QTextEdit::focusOutEvent(QFocusEvent *e)
 {
     Q_D(QTextEdit);
+    qDebug() << __FUNCTION__ << this << e;
     QAbstractScrollArea::focusOutEvent(e);
     d->sendControlEvent(e);
 }
@@ -1833,9 +1836,11 @@ void QTextEdit::changeEvent(QEvent *e)
             d->autoScrollTimer.stop();
     } else if (e->type() == QEvent::EnabledChange) {
         e->setAccepted(isEnabled());
+        qDebug() << __FUNCTION__ << this << e;
         d->control->setPalette(palette());
         d->sendControlEvent(e);
     } else if (e->type() == QEvent::PaletteChange) {
+        qDebug() << __FUNCTION__ << this << e;
         d->control->setPalette(palette());
     } else if (e->type() == QEvent::LayoutDirectionChange) {
         d->sendControlEvent(e);
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp
index cf2d885b52..19087a138b 100644
--- a/src/widgets/widgets/qwidgetlinecontrol.cpp
+++ b/src/widgets/widgets/qwidgetlinecontrol.cpp
@@ -1561,6 +1561,22 @@ void QWidgetLineControl::resetCursorBlinkTimer()
     m_blinkStatus = 1;
 }
 
+static void debugPalette(QDebug d, const char *f, const QPalette &pal)
+{
+    d << f;
+    for (auto g : {QPalette::Active, QPalette::Inactive}) {
+        d << g << "Windowtext=" << pal.color(g, QPalette::WindowText).name()
+                 << "text=" << pal.color(g, QPalette::Text).name()
+                 << "back=" << pal.color(g, QPalette::Window).name();
+    }
+}
+
+void QWidgetLineControl::setPalette(const QPalette &p)
+{
+    debugPalette(qDebug() , __FUNCTION__ , p);
+    m_palette = p;
+}
+
 void QWidgetLineControl::timerEvent(QTimerEvent *event)
 {
     if (event->timerId() == m_blinkTimer) {
diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h
index f4df95865d..cfe8f5167f 100644
--- a/src/widgets/widgets/qwidgetlinecontrol_p.h
+++ b/src/widgets/widgets/qwidgetlinecontrol_p.h
@@ -388,7 +388,7 @@ public:
     void setCancelText(const QString &text) { m_cancelText = text; }
 
     const QPalette &palette() const { return m_palette; }
-    void setPalette(const QPalette &p) { m_palette = p; }
+    void setPalette(const QPalette &p);
 
     enum DrawFlags {
         DrawText = 0x01,
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index 6b8ce63380..059c13b5d7 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -3173,15 +3173,27 @@ QPalette QWidgetTextControl::palette() const
     return d->palette;
 }
 
+static void debugPalette(QDebug d, const char *f, const QPalette &pal)
+{
+    d << f;
+    for (auto g : {QPalette::Active, QPalette::Inactive}) {
+        d << g << "Windowtext=" << pal.color(g, QPalette::WindowText).name()
+                 << "text=" << pal.color(g, QPalette::Text).name()
+                 << "back=" << pal.color(g, QPalette::Window).name();
+    }
+}
+
 void QWidgetTextControl::setPalette(const QPalette &pal)
 {
     Q_D(QWidgetTextControl);
+    debugPalette(qDebug(), __FUNCTION__, pal);
     d->palette = pal;
 }
 
 QAbstractTextDocumentLayout::PaintContext QWidgetTextControl::getPaintContext(QWidget *widget) const
 {
     Q_D(const QWidgetTextControl);
+    qDebug() << __FUNCTION__ << widget << "Focus=" << widget->hasFocus();
 
     QAbstractTextDocumentLayout::PaintContext ctx;
 
@@ -3195,6 +3207,7 @@ QAbstractTextDocumentLayout::PaintContext QWidgetTextControl::getPaintContext(QW
         else
             ctx.cursorPosition = d->cursor.position();
     }
+    debugPalette(qDebug(), __FUNCTION__, ctx.palette);
 
     if (!d->dndFeedbackCursor.isNull())
         ctx.cursorPosition = d->dndFeedbackCursor.position();
@@ -3202,6 +3215,7 @@ QAbstractTextDocumentLayout::PaintContext QWidgetTextControl::getPaintContext(QW
     if (!QApplication::keypadNavigationEnabled() || d->hasEditFocus)
 #endif
     if (d->cursor.hasSelection()) {
+        qDebug() << __FUNCTION__<< "hasSelection";
         QAbstractTextDocumentLayout::Selection selection;
         selection.cursor = d->cursor;
         if (d->cursorIsFocusIndicator) {
