Skip to content

Commit ef52134

Browse files
committed
[ui] Fix broken text annotation background color
1 parent 1114cdc commit ef52134

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/app/qgsannotationwidget.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWid
7272
}
7373
mMapMarkerButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
7474
mFrameStyleButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
75+
76+
connect( mFrameStyleButton, &QgsSymbolButton::changed, this, &QgsAnnotationWidget::frameStyleChanged );
77+
}
78+
79+
QColor QgsAnnotationWidget::backgroundColor()
80+
{
81+
return mFrameStyleButton->symbol() ? mFrameStyleButton->symbol()->color() : QColor();
82+
}
83+
84+
void QgsAnnotationWidget::frameStyleChanged()
85+
{
86+
emit backgroundColorChanged( backgroundColor() );
7587
}
7688

7789
void QgsAnnotationWidget::apply()

src/app/qgsannotationwidget.h

+9
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,25 @@ class APP_EXPORT QgsAnnotationWidget: public QWidget, private Ui::QgsAnnotationW
3333
{
3434
Q_OBJECT
3535
public:
36+
3637
QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWidget *parent = nullptr, Qt::WindowFlags f = nullptr );
3738

39+
//! Returns the annotation frame symbol fill color
40+
QColor backgroundColor();
41+
3842
void apply();
3943

44+
private:
45+
46+
void frameStyleChanged();
47+
4048
signals:
4149

4250
//! Emitted when the background color of the annotation is changed
4351
void backgroundColorChanged( const QColor &color );
4452

4553
private:
54+
4655
QgsMapCanvasAnnotationItem *mItem = nullptr;
4756

4857
void blockAllSignals( bool block );

src/app/qgstextannotationdialog.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsMapCanvasAnnotationItem *it
3838
mStackedWidget->addWidget( mEmbeddedWidget );
3939
mStackedWidget->setCurrentWidget( mEmbeddedWidget );
4040
connect( mEmbeddedWidget, &QgsAnnotationWidget::backgroundColorChanged, this, &QgsTextAnnotationDialog::backgroundColorChanged );
41-
mTextEdit->setAttribute( Qt::WA_TranslucentBackground );
41+
4242
if ( mItem && mItem->annotation() )
4343
{
4444
QgsTextAnnotation *annotation = static_cast< QgsTextAnnotation * >( mItem->annotation() );
@@ -53,6 +53,7 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsMapCanvasAnnotationItem *it
5353
mFontColorButton->setContext( QStringLiteral( "symbology" ) );
5454

5555
setCurrentFontPropertiesToGui();
56+
backgroundColorChanged( mEmbeddedWidget->backgroundColor() );
5657

5758
QObject::connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsTextAnnotationDialog::applyTextToItem );
5859
QObject::connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsTextAnnotationDialog::showHelp );
@@ -86,6 +87,7 @@ void QgsTextAnnotationDialog::backgroundColorChanged( const QColor &color )
8687
QPalette p = mTextEdit->viewport()->palette();
8788
p.setColor( QPalette::Base, color );
8889
mTextEdit->viewport()->setPalette( p );
90+
mTextEdit->setStyleSheet( QStringLiteral( "QTextEdit { background-color: %1; }" ).arg( color.name() ) );
8991
}
9092

9193
void QgsTextAnnotationDialog::applyTextToItem()

0 commit comments

Comments
 (0)