Does the QWidget::setStyleSheet function use the Q_OBJECT macro?
-
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:
But I found that if I don't write Q_OBJECT in my subclass, then the selector
.QPushButton
selects the mybtn control like below: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:(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?
-
@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.
-