Skip to content

Commit a655ec7

Browse files
committed
Fix text annotation edit background should match frame background
Otherwise white text is not visible. Fix #10553. (cherry-picked from 76c4cae)
1 parent a1c9616 commit a655ec7

4 files changed

+26
-0
lines changed

src/app/qgsannotationwidget.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsAnnotationItem* item, QWidget * par
5454
mBackgroundColorButton->setNoColorString( tr( "Transparent" ) );
5555
mBackgroundColorButton->setShowNoColor( true );
5656

57+
connect( mBackgroundColorButton, SIGNAL( colorChanged( QColor ) ), this, SIGNAL( backgroundColorChanged( QColor ) ) );
58+
5759
const QgsMarkerSymbolV2* symbol = mItem->markerSymbol();
5860
if ( symbol )
5961
{

src/app/qgsannotationwidget.h

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class APP_EXPORT QgsAnnotationWidget: public QWidget, private Ui::QgsAnnotationW
3434

3535
void apply();
3636

37+
signals:
38+
39+
//! Emitted when the background color of the annotation is changed
40+
void backgroundColorChanged( const QColor& color );
41+
3742
private slots:
3843
void on_mMapMarkerButton_clicked();
3944

src/app/qgstextannotationdialog.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsTextAnnotationItem* item, Q
2727
mEmbeddedWidget = new QgsAnnotationWidget( mItem );
2828
mStackedWidget->addWidget( mEmbeddedWidget );
2929
mStackedWidget->setCurrentWidget( mEmbeddedWidget );
30+
connect( mEmbeddedWidget, SIGNAL( backgroundColorChanged( QColor ) ), this, SLOT( backgroundColorChanged( QColor ) ) );
31+
mTextEdit->setAttribute( Qt::WA_TranslucentBackground );
3032
if ( mItem )
3133
{
3234
mTextDocument = mItem->document();
@@ -56,6 +58,18 @@ QgsTextAnnotationDialog::~QgsTextAnnotationDialog()
5658
delete mTextDocument;
5759
}
5860

61+
void QgsTextAnnotationDialog::showEvent( QShowEvent* )
62+
{
63+
backgroundColorChanged( mItem ? mItem->frameBackgroundColor() : Qt::white );
64+
}
65+
66+
void QgsTextAnnotationDialog::backgroundColorChanged( const QColor& color )
67+
{
68+
QPalette p = mTextEdit->viewport()->palette();
69+
p.setColor( QPalette::Base, color );
70+
mTextEdit->viewport()->setPalette( p );
71+
}
72+
5973
void QgsTextAnnotationDialog::applyTextToItem()
6074
{
6175
if ( mItem && mTextDocument )

src/app/qgstextannotationdialog.h

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class APP_EXPORT QgsTextAnnotationDialog: public QDialog, private Ui::QgsTextAnn
3030
QgsTextAnnotationDialog( QgsTextAnnotationItem* item, QWidget * parent = nullptr, Qt::WindowFlags f = nullptr );
3131
~QgsTextAnnotationDialog();
3232

33+
protected:
34+
35+
virtual void showEvent( QShowEvent * event ) override;
36+
3337
private:
3438
QgsTextAnnotationItem* mItem;
3539
/** Text document (a clone of the annotation items document)*/
@@ -44,6 +48,7 @@ class APP_EXPORT QgsTextAnnotationDialog: public QDialog, private Ui::QgsTextAnn
4448
void on_mFontColorButton_colorChanged( const QColor& color );
4549
void setCurrentFontPropertiesToGui();
4650
void deleteItem();
51+
void backgroundColorChanged( const QColor& color );
4752
};
4853

4954
#endif // QGSTEXTANNOTATIONDIALOG_H

0 commit comments

Comments
 (0)