-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.4.0, 5.5.0, 5.15.4
-
None
Running the following example on Mac, the selection gets a gray color.
It would be expected that it would have the native selection color.
On Mac this would be specially seen if going into "System Preferences" and then changing highlight color to orange.
When deselecting the area, then reselecting it again it gets the correct color.
#include <QtGui> #include <QDebug> class CustomWidget : public QPushButton { Q_OBJECT public: CustomWidget(QWidget* parent=0) : QPushButton(parent) { connect(this,SIGNAL(clicked()), this, SLOT(aSlot())); } QTextEdit *edit; public slots: void aSlot() { qDebug() << "aSlot invoked"; QTextCursor highlightCursor = edit->textCursor(); QTextCharFormat plainFormat(highlightCursor.charFormat()); QTextCharFormat colorFormat = plainFormat; colorFormat.setFontWeight(QFont::Bold); colorFormat.setBackground(Qt::blue); highlightCursor.movePosition(QTextCursor::WordRight,QTextCursor::KeepAnchor); highlightCursor.mergeCharFormat(colorFormat); edit->setTextCursor(highlightCursor); } protected: void paintEvent(QPaintEvent *pe) { QPushButton::paintEvent(pe); } }; #include "main.moc" int main(int argc, char *argv[]) { QApplication app(argc, argv); CustomWidget wid; wid.show(); QTextEdit edit; wid.edit = &edit; edit.setHtml("<html><body>hello worldasdf<br><br><br><br><br><br><br><br> asd f asdf asdf adfs adfs <br><br><br><br>adfsasdfadfs <br><br>adfs fads dfsa</body></html>"); QTimer::singleShot(6000, &wid, SLOT(aSlot())); edit.show(); return app.exec(); }