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. Does the QWidget::setStyleSheet function use the Q_OBJECT macro?
Forum Updated to NodeBB v4.3 + New Features

Does the QWidget::setStyleSheet function use the Q_OBJECT macro?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 221 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
    mq-loser
    wrote on last edited by
    #1

    I'm having a problem learning Qt stylesheets. A question about style sheet selectors.

    The first thing is that qt documentation says that the selector .QPushButton : Matches instances of QPushButton, but not of its subclasses.

    So I defined mybtn as a class inheriting from QPushButton. Shouldn't mybtn be a subclass of QPushButton at this point? Here's how it looks:

    ce27db04-a402-4b26-bb2c-943ba4a94b64-image.png

    But I found that if I don't write Q_OBJECT in my subclass, then the selector .QPushButton selects the mybtn control like below:

    102f1919-94d6-4363-b585-03956b5d6d9d-image.png

    Only if I write Q_OBJECT in my subclasses does it Matches instances of QPushButton, but not of its subclasses. as the qt documentation says, below:

    7617d270-7fb4-4160-86fd-22250fdf2a68-image.png

    (Note: the contents of the style.qss file have not been changed)

    Since I'm using the setStyleSheet function to set the style sheet, I'm curious as to where setStyleSheet uses the Q_OBJECT macro?

    sierdzioS 1 Reply Last reply
    0
    • M mq-loser

      I'm having a problem learning Qt stylesheets. A question about style sheet selectors.

      The first thing is that qt documentation says that the selector .QPushButton : Matches instances of QPushButton, but not of its subclasses.

      So I defined mybtn as a class inheriting from QPushButton. Shouldn't mybtn be a subclass of QPushButton at this point? Here's how it looks:

      ce27db04-a402-4b26-bb2c-943ba4a94b64-image.png

      But I found that if I don't write Q_OBJECT in my subclass, then the selector .QPushButton selects the mybtn control like below:

      102f1919-94d6-4363-b585-03956b5d6d9d-image.png

      Only if I write Q_OBJECT in my subclasses does it Matches instances of QPushButton, but not of its subclasses. as the qt documentation says, below:

      7617d270-7fb4-4160-86fd-22250fdf2a68-image.png

      (Note: the contents of the style.qss file have not been changed)

      Since I'm using the setStyleSheet function to set the style sheet, I'm curious as to where setStyleSheet uses the Q_OBJECT macro?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @mq-loser said in Does the QWidget::setStyleSheet function use the Q_OBJECT macro?:

      setStyleSheet uses the Q_OBJECT macro?

      This macro is necessary for all QObject subclasses. You should always use it. It allows Qt to set up meta object information properly, and that info is what QSS uses.

      (Z(:^

      M 1 Reply Last reply
      3
      • M mq-loser has marked this topic as solved on
      • sierdzioS sierdzio

        @mq-loser said in Does the QWidget::setStyleSheet function use the Q_OBJECT macro?:

        setStyleSheet uses the Q_OBJECT macro?

        This macro is necessary for all QObject subclasses. You should always use it. It allows Qt to set up meta object information properly, and that info is what QSS uses.

        M Offline
        M Offline
        mq-loser
        wrote on last edited by
        #3

        @sierdzio Thanks for your answer.

        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