Skip to content

Commit 76282d5

Browse files
committed
Fix layout issues with color button editor widget
- widget was not left aligned - widget would shrink to a small vertical height in crowded forms
1 parent 4c704be commit 76282d5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/gui/editorwidgets/qgscolorwidgetwrapper.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
***************************************************************************/
1515

1616
#include "qgscolorwidgetwrapper.h"
17+
#include <QLayout>
1718

1819
QgsColorWidgetWrapper::QgsColorWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
1920
: QgsEditorWidgetWrapper( vl, fieldIdx, editor, parent )
@@ -42,14 +43,26 @@ void QgsColorWidgetWrapper::showIndeterminateState()
4243

4344
QWidget* QgsColorWidgetWrapper::createWidget( QWidget* parent )
4445
{
45-
QgsColorButtonV2* button = new QgsColorButtonV2( parent );
46+
QWidget* container = new QWidget( parent );
47+
QHBoxLayout* layout = new QHBoxLayout();
48+
container->setLayout( layout );
49+
layout->setMargin( 0 );
50+
layout->setContentsMargins( 0, 0, 0, 0 );
51+
QgsColorButtonV2* button = new QgsColorButtonV2();
4652
button->setContext( QString( "editor" ) );
47-
return button;
53+
layout->addWidget( button );
54+
layout->addStretch();
55+
container->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
56+
return container;
4857
}
4958

5059
void QgsColorWidgetWrapper::initWidget( QWidget* editor )
5160
{
5261
mColorButton = qobject_cast<QgsColorButtonV2*>( editor );
62+
if ( !mColorButton )
63+
{
64+
mColorButton = editor->findChild<QgsColorButtonV2*>();
65+
}
5366

5467
connect( mColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( valueChanged() ) );
5568
}

0 commit comments

Comments
 (0)