You said you were on KDE, I have the same issue, which this post was helpful to find the root cause.
First xrdb -query -all | grep -i emacs
, revealed some entries for Emacs which I didn't set myself:
$ xrdb -query -all | grep -i emacs
Emacs*Background: #fcfcfc
Emacs*Dialog*background: #eff0f1
Emacs*Dialog*foreground: #31363b
Emacs*Foreground: #31363b
...
Searching the disk for the files defining these entries I found:
$ grep -Fnr 'Emacs*XlwScrollBar' /etc /usr/share 2>/dev/null
/usr/share/kdisplay/app-defaults/Emacs.ad:12:Emacs*XlwScrollBar.Foreground: FOREGROUND
/usr/share/kdisplay/app-defaults/Emacs.ad:13:Emacs*XlwScrollBar.Background: BACKGROUND
By searching about this file /usr/share/kdisplay/app-defaults/Emacs.ad
, I found this old but relevant thread on the Emacs mailing list:
Apparently KDE sets some X resources for applications like Emacs,
so that the application look'n'feel matches the KDE theme.
This thread suggests to remove only the attributes that aren't desired but to keep others so the look'n'feel stays close to the KDE theme:
In this way, KDE still changes the colors/fonts of other applications
AND also some things in Emacs (like the Menubar for example, which matches the KDE-menus colors/font).
Note: I could not find a difference in the look'n'feel after commenting the whole file, so it's possible that this is no longer needed even for Menubar and other graphical elements that the resource file sets.
My issue was just the cursor color, which is solved by commenting Emacs*Foreground
:
Emacs.default.attributeForeground: WINDOW_FOREGROUND
Emacs.default.attributeBackground: WINDOW_BACKGROUND
! breaks Emacs cursor color
! Emacs*Foreground: WINDOW_FOREGROUND
Emacs*Background: WINDOW_BACKGROUND
Emacs*menubar*foreground: FOREGROUND
Emacs*menubar*background: BACKGROUND
...