Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Setting the background color of a QFrame object ignored

Setting the background color of a QFrame object ignored

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    giusdbg
    wrote on last edited by giusdbg
    #1

    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?
    Screenshot_20230528_125722.png

    JonBJ 1 Reply Last reply
    0
    • G giusdbg

      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?
      Screenshot_20230528_125722.png

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @giusdbg
      Does the "other project" use stylesheets?

      G 1 Reply Last reply
      0
      • JonBJ JonB

        @giusdbg
        Does the "other project" use stylesheets?

        G Offline
        G Offline
        giusdbg
        wrote on last edited by giusdbg
        #3

        @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 );
        
        
        JonBJ 1 Reply Last reply
        0
        • G giusdbg

          @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 );
          
          
          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @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.

          G 1 Reply Last reply
          1
          • JonBJ JonB

            @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.

            G Offline
            G Offline
            giusdbg
            wrote on last edited by
            #5

            @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.

            G 1 Reply Last reply
            0
            • G giusdbg

              @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.

              G Offline
              G Offline
              giusdbg
              wrote on last edited by giusdbg
              #6

              @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 );
              
              1 Reply Last reply
              2
              • G giusdbg has marked this topic as solved on

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved