Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 通过QStyle设置背景色

通过QStyle设置背景色

Scheduled Pinned Locked Moved Chinese
1 Posts 1 Posters 3.3k 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.
  • H Offline
    H Offline
    harris_
    wrote on last edited by
    #1

    在使用QStyle设置背景色的时候,我在函数
    @void MyStyle::polish(QPalette& pal)
    {
    pal.setBrush(QPalette::Window, QColor(71, 99, 128));
    }@

    中通过QPalette::Window来设置背景色,但是这样设置整个应用都是一样的背景色,如果我要修改某一个widget的背景色的时候,我通过
    @QPalette pal(palette());
    pal.setBrush(QPalette::Background, Qt::lightGray);
    setPalette(pal);@

    来设置某一个widget的背景,但是这样设置就会把这个widget的子widget的背景色也设置为一样的了,有没有方法可以达到
    @QWidget* widget= new QWidget();
    widget->setObjectName("widget");
    widget->setStyleSheet("QWidget#widget{background-color:lightGray}");@

    设置stylesheet中用#指定窗口的效果,但是是通过QStyle来设置。
    谢谢!

    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