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 relationship between paintEvent and style sheet of a QWidget?
Forum Updated to NodeBB v4.3 + New Features

What is the relationship between paintEvent and style sheet of a QWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.4k 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.
  • M Offline
    M Offline
    MartinChan 0
    wrote on last edited by
    #1

    I want to know what is the relationship between paintEvent ann stylesheet of one single widget?I know the QWidget obey Box Model ,so does that mean when we implent the paintEvent() we only draw in the "Content Region" of Box Model ?
    boxModel

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

      Hi
      StyleSheets are used by QStyle and it drawX functions.
      so to use stylesheet in (custom) paintEvent, one must use QStyle to draw.
      QPainter itself knows nothing about the stylesheets.

      void CustomWidget::paintEvent(QPaintEvent *)
       {
           QStyleOption opt;
           opt.init(this);
           QPainter p(this);
           style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
       }
      

      Above code makes CustomWidget respect StyleSheet.

      1 Reply Last reply
      4

      • Login

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