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. What is the alternate for StyleSheet to set the background and bottom border of a custom widget derived from the QWidget?
Qt 6.11 is out! See what's new in the release blog

What is the alternate for StyleSheet to set the background and bottom border of a custom widget derived from the QWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 441 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.
  • T Offline
    T Offline
    thomasjohnaj
    wrote on last edited by
    #1

    I Have a custom widget derived from QWidget

    it contain two labels. Now I want to fill the background of the Custom widget ( which include the child widget) with red and set the bottom border with 2px thickness and color dark red. I dont want to use stylesheet, since its organization policy to rely less on style sheet.

    What i tried?

    I override the paintevent and have made use of the below code to fill the rectangle

    QPainter painter(this);
    painter.fillRect(rect(), QColor(170,30,330));

    this worked for me. I am still in a doubt how to set the border width and color.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You can look how QFrame does.

      void QFrame::drawFrame(QPainter *p)
      {
          QStyleOptionFrame opt;
          initStyleOption(&opt);
          style()->drawControl(QStyle::CE_ShapedFrame, &opt, p, this);
      }
      

      However, it would be easier to just inherit from QFrame instead so you can just set properties and
      not values in QStyleOptionFrame.

      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 Extensions
      • Unsolved