StyleSheet
Unsolved
General and Desktop
-
Hello
Why when I set stylesheet for my QPushButton:hover background, the background area is bigger than an actual QPushButton?
My code:
button->setStyleSheet("QPushButton:hover { background: Red;}");
-
Hi,
What version of Qt ?
On what platform ?
What are you getting ?
Can you provide a minimal compilable example that shows that behaviour ? -
Can you provide a minimal compilable example ?
-
widget.cpp:
#include "widget.h" #include "ui_widget.h" #include <QPushButton> Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); auto button = new QPushButton(this); button->setStyleSheet("QPushButton:hover { background: Red;}"); }
widget.h:
#ifndef WIDGET_H #define WIDGET_H #include <QWidget> QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACE class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); private: Ui::Widget *ui; }; #endif // WIDGET_H
main.cpp:
#include "widget.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); }
-
If you a better looking button with style sheets, you should take a look at the customizing QPushButton example in the Qt Stylesheet reference.