Setting the background color of a QFrame object ignored
-
Hi.
I'm trying to set the background color of a QFrame object.
If I do it from Qt Creator it works fine (see below), if I do it in another project's code the setting is ignored.QPalette pal; pal.setColor( QPalette::Base, Qt::black ); framePanel->setPalette(pal);I tried a little bit of everything but it was all ignored, does anyone have a solution, any ideas?

-
Hi.
I'm trying to set the background color of a QFrame object.
If I do it from Qt Creator it works fine (see below), if I do it in another project's code the setting is ignored.QPalette pal; pal.setColor( QPalette::Base, Qt::black ); framePanel->setPalette(pal);I tried a little bit of everything but it was all ignored, does anyone have a solution, any ideas?

-
@JonB It's a bit of a complex project and I don't fully master it, but I'd say definitely not.
A few more pieces of code, if that helps.
My feeling is that the QFrame object is in transparent mode.framePanel = new QFrame( this ); framePanel->setMinimumSize( QSize( 64, 64 ) ); framePanel->setMaximumSize( QSize( 64, 64 ) ); .................... framePanel->setPalette( pal ); framePanel->setFrameShape( QFrame::Panel ); framePanel->setFrameShadow( QFrame::Raised ); labelTitle = new QLabel( framePanel ); labelTitle->setGeometry( QRect( 8, 40, 50, 20 ) ); QFont labelTitle_font( labelTitle->font() ); labelTitle_font.setPointSize( 7 ); labelTitle->setFont( labelTitle_font ); labelTitle->setAlignment( Qt::AlignCenter ); labelValue = new QLabel( framePanel ); labelValue->setGeometry( QRect( 7, 16, 50, 20 ) ); labelValue->setAlignment( Qt::AlignCenter ); PaletteCfgDesignLayout->addWidget( framePanel, 0, 0, 0, 1 ); -
@JonB It's a bit of a complex project and I don't fully master it, but I'd say definitely not.
A few more pieces of code, if that helps.
My feeling is that the QFrame object is in transparent mode.framePanel = new QFrame( this ); framePanel->setMinimumSize( QSize( 64, 64 ) ); framePanel->setMaximumSize( QSize( 64, 64 ) ); .................... framePanel->setPalette( pal ); framePanel->setFrameShape( QFrame::Panel ); framePanel->setFrameShadow( QFrame::Raised ); labelTitle = new QLabel( framePanel ); labelTitle->setGeometry( QRect( 8, 40, 50, 20 ) ); QFont labelTitle_font( labelTitle->font() ); labelTitle_font.setPointSize( 7 ); labelTitle->setFont( labelTitle_font ); labelTitle->setAlignment( Qt::AlignCenter ); labelValue = new QLabel( framePanel ); labelValue->setGeometry( QRect( 7, 16, 50, 20 ) ); labelValue->setAlignment( Qt::AlignCenter ); PaletteCfgDesignLayout->addWidget( framePanel, 0, 0, 0, 1 ); -
@giusdbg
Then you will have to track that down. usual procedure is to try what you have in a standalone, tiny program, then if it works find out how yours differs. -
@JonB It will be difficult to do this, because the other application is kde.
It occurs to me that I've ruled out your assumption, but it could be some part of kde doing this.
@JonB I was lucky, it stopped working in Qt Creator as well 🤣 .
And having a minimum of more experience I went to the bottom.Apparently in Qt Creator it worked by mistake, it was enough to mess around for a minimum and it didn't work anymore.
The solution
framePanel->setAutoFillBackground( true ); -
G giusdbg has marked this topic as solved on