Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What palette role/attribute sets the line color of QFrame "setLineWidth" ?
Qt 6.12 LTS is out! See what's new in the release blog

What palette role/attribute sets the line color of QFrame "setLineWidth" ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 847 Views 2 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.
  • E Offline
    E Offline
    edmh
    wrote on last edited by
    #1

    Hello -
    I am looking to change the color of the line drawn around the edge of a QFrame using this code:

    QFrame* frameA = new QFrame(centralWidget)
    frameA->setFrameShape(QFrame::Box);
    frameA->setFrameShadow(QFrame::Sunken);
    frameA->setLineWidth(2);
    frameA->setMidLineWidth(4);

    If I do this:
    QBrush brush1(QColor(127, 127, 127, 255));
    brush1.setStyle(Qt::SolidPattern);
    palette.setBrush(QPalette::Active, QPalette::Mid, brush1);

    Then the line drawn for "setMindLineWidth" is grey, as expected.
    But the line drawn from 'setLineWidth(2)' is always white. How do I change that color?

    And yes, I have don this:

    QBrush brush3(QColor(255, 0, 0 255));
    brush.setStyle(Qt::SolidPattern);
    palette.setBrush(QPalette::Active, QPalette::WindowText, brush3);
    palette.setBrush(QPalette::Active, QPalette::Text, brush3);
    

    I am using Qt5 and I do NOT want to use style sheet.
    Operating system is Linux / Xorg

    Thanks

    1 Reply Last reply
    0
    • C Offline
      C Offline
      CPPUIX
      wrote on last edited by
      #2

      Hi,

      I'm not sure I understand (a screenshot of your current result would be helpful), but I'm guessing the shadow color is what you mean.

      From QFrame documentation:

      QFrame::Sunken : the frame and contents appear sunken; draws a 3D sunken line using the light and dark colors of the current color group

      So try this:

      QFrame* frameA = new QFrame();
      frameA->setFrameShape(QFrame::Box);
      frameA->setFrameShadow(QFrame::Sunken);
      frameA->setLineWidth(2);
      frameA->setMidLineWidth(4);
      
      QBrush brush1(QColor(127, 127, 127, 255));
      brush1.setStyle(Qt::SolidPattern);
      
      QPalette palette=frameA->palette();
      //shadow color, dark and light palette roles
      palette.setBrush(QPalette::Active, QPalette::Light, brush1);
      palette.setBrush(QPalette::Active, QPalette::Dark, brush1);
      
      //mid line color
      palette.setBrush(QPalette::Active, QPalette::Mid, brush1);
      frameA->setPalette(palette);
      
      frameA->show();
      

      Is this the result you're looking for?

      framecolor.png

      E 1 Reply Last reply
      1
      • C CPPUIX

        Hi,

        I'm not sure I understand (a screenshot of your current result would be helpful), but I'm guessing the shadow color is what you mean.

        From QFrame documentation:

        QFrame::Sunken : the frame and contents appear sunken; draws a 3D sunken line using the light and dark colors of the current color group

        So try this:

        QFrame* frameA = new QFrame();
        frameA->setFrameShape(QFrame::Box);
        frameA->setFrameShadow(QFrame::Sunken);
        frameA->setLineWidth(2);
        frameA->setMidLineWidth(4);
        
        QBrush brush1(QColor(127, 127, 127, 255));
        brush1.setStyle(Qt::SolidPattern);
        
        QPalette palette=frameA->palette();
        //shadow color, dark and light palette roles
        palette.setBrush(QPalette::Active, QPalette::Light, brush1);
        palette.setBrush(QPalette::Active, QPalette::Dark, brush1);
        
        //mid line color
        palette.setBrush(QPalette::Active, QPalette::Mid, brush1);
        frameA->setPalette(palette);
        
        frameA->show();
        

        Is this the result you're looking for?

        framecolor.png

        E Offline
        E Offline
        edmh
        wrote on last edited by
        #3

        @Abderrahmene_Rayene said in What palette role/attribute sets the line color of QFrame "setLineWidth" ?:

        palette.setBrush(QPalette::Active, QPalette::Light, brush1);

        Yes, thank you.
        So the answer to my question is

        alette.setBrush(QPalette::Active, QPalette::Light, brush1);
        palette.setBrush(QPalette::Active, QPalette::Dark, brush1);

        1 Reply Last reply
        0

        • Login

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