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. Qt Stylesheet mystery
Qt 6.11 is out! See what's new in the release blog

Qt Stylesheet mystery

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 5.9k 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.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    My Desktop Qt app has a large stylesheet applied. It's applied for the QApplication derived class I am using:

    @this->ApplyStyleSheet(":/qss/default.qss");@

    It works well for all QWidget objects I define and use. (using *.ui files).

    My problem begins when i promote one of my QWidgets in the *.ui file I'm using to one of my own QWidget derived classes.

    When my widget was QWidget, the following worked and changed the background image:

    @QWidget#myWidget {
    background: transparent;
    background-image: url(:/images/bg_img.png);
    background-repeat: repeat-x;
    }@

    When I promoted the element to my custom QWidget derived class and changed to:

    @QMyDerivedClass#myWidget {
    background: transparent;
    background-image: url(:/images/bg_img.png);
    background-repeat: repeat-x;
    }@

    I no longer see my background image. Obviously I am missing something. What is it... I hope one of you knows.

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      I've seen this before with promoting widgets.

      The only solution i could find is to do al stylesheet stuff in code not in Qt Designer.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3

        It's a FAQ. Read the entry for QWidget in here: [[doc:stylesheet-reference]]

        [quote]
        If you subclass from QWidget, you need to provide a paintEvent for your custom QWidget as below:
        @
        void CustomWidget::paintEvent(QPaintEvent *)
        {
        QStyleOption opt;
        opt.init(this);
        QPainter p(this);
        style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
        }
        @

        The above code is a no-operation if there is no stylesheet set.

        Warning: Make sure you define the Q_OBJECT macro for your custom widget.
        [/quote]

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • R Offline
          R Offline
          ronM71
          wrote on last edited by
          #4

          that did it. my bad. thanks.

          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