Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. stylesheet
    Log in to post

    • SOLVED Style application bar (the top bar of a floating window) which has the close and minimize buttons
      General and Desktop • stylesheet window windows10 close minimize • • Hologram  

      3
      0
      Votes
      3
      Posts
      29
      Views

      Well, Qt does not provide these capabilities. This means that you cannot easily use stylesheets for this purpose. However, there might be OS-specific ways to change the color of the title bar. On Windows (10 and later) you can use DwmSetWindowAttribute to enable dark mode for the title bar. Another way is to get a window without decoration/borders from the OS and then draw the entire title bar yourself using Qt. Then, you can also style the title bar using stylesheets. It might get a little complicated to draw the close and minimize buttons in the correct OS style yourself.
    • UNSOLVED Extend Qmenu::separator over the Qmenu margin (so it touches the edges)?
      General and Desktop • stylesheet qmenu qss separator margin • • Hologram  

      1
      0
      Votes
      1
      Posts
      15
      Views

      No one has replied

    • UNSOLVED Edit scrollbar colour through stylesheet in main window?
      General and Desktop • stylesheet mainwindow qscrollbar scrollbar scroll • • Hologram  

      6
      0
      Votes
      6
      Posts
      48
      Views

      Don't you have access to the source code ? And if not, ask the authors ?
    • UNSOLVED QToolButton with margin is clickable
      General and Desktop • stylesheet margin • • leonardo M B  

      6
      0
      Votes
      6
      Posts
      110
      Views

      Since it changes geometry of the items after maybe it's another quirk. Try calling QStyle::unpolish and then QStyle::polish() with the toolbar.
    • SOLVED Palette overriding style sheet
      General and Desktop • stylesheet style palette • • aljoachim  

      8
      0
      Votes
      8
      Posts
      194
      Views

      @JonB said in Palette overriding style sheet: Any reason why you didn't use, say, static QPushButton dummyButton; here? I guess I fumbled to long to actually get the style sheet to apply. I tried many different things (because I didn't see this documented anywhere). Must have overlooked this when cleaning up. Thank you! Will fix it in my code.
    • SOLVED Stylesheet css or xml widgets pyqt6 python
      Qt 6 • python stylesheet css xml qtwidgets • • Jbone73  

      5
      0
      Votes
      5
      Posts
      323
      Views

      @jsulm Thank you very much ! It's exactly what I needed. In the top !
    • UNSOLVED After using my Qt desktop application for a while and also using other applications simultaneously the stylesheet of my Qt desktop application changes.
      General and Desktop • stylesheet desktop • • andyP  

      2
      0
      Votes
      2
      Posts
      138
      Views

      @andyP said in After using my Qt desktop application for a while and also using other applications simultaneously the stylesheet of my Qt desktop application changes.: But after a while using my application and other programs simultaneously the stylesheets changes. I don't think anyone can diagnose this. However when the stylesheet changes the button is instead shown as light blue when starting: If you replace the first stylesheet rule by the second one you will lose the first stylesheet's green foreground/background, if that is what you mean. Then the light blue presumably comes from some other applicable rule you have.
    • UNSOLVED StyleSheet not applying when a child is declared
      General and Desktop • qwidget stylesheet inheritance • • Dzious  

      1
      0
      Votes
      1
      Posts
      128
      Views

      No one has replied

    • UNSOLVED Is there a better method than calling polish recursively on all children of a QWidget?
      General and Desktop • qwidget stylesheet property propertychanges polish • • letop  

      3
      0
      Votes
      3
      Posts
      714
      Views

      @JonB Thank you for your feedback. Going thorugh the existing children lists and filter the widgets in specific code is surely a bit more efficient with regards to speed, but that's not the kind of optimisation I was looking for. Some frameworks have a dirty flag for instance that triggers an evalution by the graphics system when it is due for evaluation (on 20ms ticks for instance). The polish/unpolish functions could benefit from a better documentation. I have a stylesheet only at the QApplication level, I empty all other stylesheets that are set by QtDesigner - I use the only for that. I use the same "style()" because it works and it probably is a small performance gain. I haven't tried polishing the application itself, and I suppose that is an overkill for just updating a few widgets. The default implementation of (un)polish does nothing, but QStylesheetStyle does. It seems to wrap the baseStyle(), which is likely something like QWindowsStyle or QFusionStyle which do nothing. But that's doing exactly what is needed then, only the stylesheet impacts the layout and the QStylesheetStyle handles that. QWidget::ensurePolished works recursively, but polishes only "unpolished" QWidgets in the end. Upon examination of the QStylesheetStyle code, it seems that unpolishing may not be needed. So I am removing that from the "recursive" implementation and I'll see if it's ok. It seems to avoid quite a few unnecessary operations! Update: polishing "recursively" is just enough.
    • UNSOLVED How to properly style QComboBox and dropdown?
      General and Desktop • stylesheet combobox drop-down combobox style combobox macos • • arjun98  

      3
      0
      Votes
      3
      Posts
      283
      Views

      @nagesh No style sheet, however, I had experiemented with the stylesheet in the link that you sent, and I couldn't figure it out. Which fields pertain to the width of the drop-down? There is a horizontal layout, however, I have also tried without layout and I get the same issue. I can control the width of the Combobox when it is closed, but once open there is an offset, that is what I would like to remove. Thank you, Arjun
    • SOLVED Replicating double borders with QSS
      General and Desktop • stylesheet qss • • QueTeeHelper  

      5
      0
      Votes
      5
      Posts
      457
      Views

      You can read the class sources.
    • UNSOLVED How to remove QPushButton border but keep effect
      General and Desktop • stylesheet qpushbutton qicon • • dporobic  

      3
      0
      Votes
      3
      Posts
      823
      Views

      Yes, it was a custom widget in title bar. I wasn't able to figure out where this is coming from so I went with a different solution but still strange behavior.
    • UNSOLVED What is the exact code to change PushButton background-color onclick in the button's stylesheet in Qt Designer?
      General and Desktop • stylesheet pyqt5 python3 qt designer pushbutton • • I-TECH  

      3
      0
      Votes
      3
      Posts
      261
      Views

      @JonB Thank you for interactions. Would you please show me an exact code of for example a PushButton and where to implement it. I am advanced python coder, I just need to see exact steps. Thank you very much.
    • SOLVED QPushButton with border-image & 50% radius has pixelated border
      General and Desktop • stylesheet qpushbutton borderimage border-radius • • MF_DANTE  

      3
      0
      Votes
      3
      Posts
      1205
      Views

      I was randomly trying to look for answers, and found out, even if that was not supposed to be the answer to my question, that : using "border-image" instead of "background-image" or "image" literally remove the pixelized stuff and SOVLES IT ONCE FOR ALL !
    • UNSOLVED Custom QCheckbox in QT widgets
      General and Desktop • stylesheet qtablewidget qtwidgets qcheckbox • • EagleSparrow  

      3
      0
      Votes
      3
      Posts
      382
      Views

      Here is the code. QList<SomeClass> ModeTableEntries ; for (int row = 0; row < ModeTableEntries .length(); row++) { ui->EntriesTableWidget->insertRow(row); ui->EntriesTableWidget->setRowHeight(row, 45); ModeValues value = ModeTableEntries [row]; QTableWidgetItem* currentItem = new QTableWidgetItem(value .ModeText); if(TestModeEnabled == true) currentItem->setCheckState(Qt::Checked); else currentItem->setCheckState(Qt::Unchecked); ui->EntriesTableWidget->setItem( row, 0, currentItem); currentItem->setFlags(currentItem->flags()^(Qt::ItemIsEditable )); } The problem is that I cannot style the default implementation of the QTableWidgetItem(QCheckbox) that is part of the QTableWidgetItem.
    • SOLVED How to set StyleSheet for an specific label in QMessageBox?
      General and Desktop • c++ stylesheet css qmessagebox • • Muhammad Mirab Br.  

      8
      0
      Votes
      8
      Posts
      3903
      Views

      Thanks @Bonnie, You are AWESOME!
    • SOLVED How to make a Text wrap delegate use the treeviews stylesheet
      General and Desktop • stylesheet treeview qstyleditemdele • • sailord  

      6
      0
      Votes
      6
      Posts
      447
      Views

      @sailord So it did use SizeHint but it was just returning too small value ? Super :)
    • UNSOLVED Custom QScrollBar
      QML and Qt Quick • qml stylesheet custom widget qscrollbar • • Emrecp  

      2
      0
      Votes
      2
      Posts
      353
      Views

      Hi I don't think Qt stylesheet supports even half of this #style-9::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); background-color: #F5F5F5; } so you best bet is to dig into https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qscrollbar and see how close you can get it.
    • SOLVED Runtime notification regarding stylesheet
      General and Desktop • stylesheet parsing • • qt_emp  

      6
      0
      Votes
      6
      Posts
      264
      Views

      @qt_emp Hi Yes it will work. https://doc.qt.io/archives/qt-4.8/qtglobal.html#qInstallMsgHandler (name is slightly different. works the same as far as i know)
    • SOLVED Why my scrollbar track color is transparent?
      General and Desktop • stylesheet pyside2 pyqt5 pyqt scroll bar • • Ishaq Khan  

      11
      0
      Votes
      11
      Posts
      3498
      Views

      @mrjj Thank you very much! Problem solved.
    • SOLVED How to edit the style of QActions?
      General and Desktop • stylesheet qaction • • rrd0  

      6
      0
      Votes
      6
      Posts
      883
      Views

      @mrjj show me the right path and I found a solution. QToolButton:!checked { border: none; }
    • UNSOLVED QComboBox and QAbstractSpinBox custom stylesheet affects arrow buttons
      General and Desktop • stylesheet qcombobox gradient qabstractspinbo • • sadeq  

      1
      0
      Votes
      1
      Posts
      356
      Views

      No one has replied

    • SOLVED Change background for hover item in QFontComboBox?
      General and Desktop • stylesheet hover combobox style • • legitnameyo  

      7
      0
      Votes
      7
      Posts
      1263
      Views

      @mrjj your file works like a charm! Thanks for the help!
    • SOLVED Problem: Stylesheet for QGroupBox
      General and Desktop • stylesheet qgroupbox • • willemf  

      3
      0
      Votes
      3
      Posts
      1881
      Views

      @J.Hilk Merci beaucoup, JH, c'est parfait! wf
    • SOLVED Button inherit stylesheet for no reason
      General and Desktop • stylesheet mouseevent qpushbutt • • legitnameyo  

      17
      0
      Votes
      17
      Posts
      1595
      Views

      @KillerSmath fix did the work, combined with @mrjj QGroupButton! I added this code to style the pressed button void MainWindow::onGroupButtonClicked(int btn_id) { g_btns->button(btn_id)->setStyleSheet(QString("QPushButton {color: #444444; background: #cccccc; border: 2px solid #cccccc; border-width: 0px 0px 2px 0px;} QPushButton:hover {border: 2px black solid; color: #333333; background-color: #F7F7F7;} QPushButton:pressed {background: #cccccc;}")); } Thanks a lot guys!
    • SOLVED Styling QPushButton border doesn't work properly on latest Qt with MacOS??
      General and Desktop • stylesheet macos qpushbutt • • legitnameyo  

      2
      0
      Votes
      2
      Posts
      845
      Views

      That's not valid css. border does not take 4 separate width parameters, only one shared across all sides. If you want to set borders different for each side you need to use border-width: border: solid #000000; border-width: 0px 0px 2px 0px;
    • UNSOLVED QTableWidgetItem set background color on click (over stylesheet )
      General and Desktop • stylesheet qtablewidget • • nevdokimof  

      15
      0
      Votes
      15
      Posts
      8589
      Views

      Delegate widget has to be used.
    • SOLVED QFrame with layout and comboBoxes insight => setStylesSheet calls index method of QAbstractItemModel of connected comboBoxes
      General and Desktop • stylesheet performance qabstractitemmo qframe • • Dagginio  

      11
      0
      Votes
      11
      Posts
      1393
      Views

      @Dagginio Hi just call update() to have it refresh when "status" changes. -Do I have to remove that blue frame before I paint a grey one? depends if you have autofillbackground on widget on. in that case it will be cleared default. else u might have to. try without and see
    • UNSOLVED Confused about how style sheet inheritance works
      Qt WebKit • stylesheet qwebview css qt 4.8 • • define-qt  

      5
      0
      Votes
      5
      Posts
      1739
      Views

      @define-qt You can be more specific using the name of object as identifier in style sheet sintaxe QLineEdit#ObjectName { border:0; }
    • UNSOLVED Padding/Margin is not applied to last two elements in QTreeView
      General and Desktop • stylesheet qtreeview qtreewidget • • JoseTomasTocino  

      6
      0
      Votes
      6
      Posts
      3760
      Views

      A late reply, but it looks like those elements are different in that they don't have children. Have you checked that you don't have a style with QTreeView::item:!has-children { padding: ... } defined anywhere which could be overriding the style when applied at the branch level?
    • SOLVED Customizing ScrollBar of QListWidget
      General and Desktop • stylesheet qlistwidget qscrollbar • • mounipanditi  

      5
      0
      Votes
      5
      Posts
      4061
      Views

      @raven-worx my bad, Thanks for the link it helped a lot.
    • SOLVED Qt Style Sheets cascading classes selectors
      General and Desktop • stylesheet qcss • • JonB  

      29
      1
      Votes
      29
      Posts
      23990
      Views

      To summarise for anyone reading this. Thanks to the answers above. You can assign a dynamic property, with a name and value of your choice, via QWidget.setProperty("cssClass", "large"). The stylesheet can match this via selector *[cssClass="large"] { ... }. You can assign multiple values to the property via QWidget.setProperty("cssClass", [ "bold", "large", "rounded" ]). (Or it accepts a space-separated string via "bold large rounded".) The stylesheet can match one of the values via selector *[cssClass~="large"] { ... } (note the ~=). Note that property named class is a special one, referring to the Python/C++ code class of the widget, which you probably should not assign to.
    • UNSOLVED Android: QToolBar doesn't forward stylesheet to children
      Mobile and Embedded • android stylesheet • • Gloweye  

      1
      0
      Votes
      1
      Posts
      464
      Views

      No one has replied

    • SOLVED Qt Widgets global stylesheet
      General and Desktop • stylesheet qtwidgets • • Tikani  

      8
      0
      Votes
      8
      Posts
      9202
      Views

      If you want stylesheet ready for the use of qss in your application use this site: https://qss-stock.devsecstudio.com
    • SOLVED QTabWidget TabBar font size weirdness
      General and Desktop • stylesheet qtabwidget font size qtabbar • • pauledd  

      3
      0
      Votes
      3
      Posts
      6671
      Views

      Thank you! I see you specified height and width manually. That works so far. I will use that.
    • SOLVED Customizing QMainWindow by style sheet
      General and Desktop • stylesheet qmainwindow css qt5.8 • • eDeviser  

      5
      0
      Votes
      5
      Posts
      10271
      Views

      @eDeviser said in Customizing QMainWindow by style sheet: Yes, this helps! I see the QMainWindow holds a QWidget which is set as cetralWidget. So It would be necessary to set the QMainWindow as centralWidget or to apply my css for the QWidget. Thank you for this hint. You have to apply your css in your qwidget ! Your css should be : centralWidget { background: yellow; width: 10px; /* when vertical / height: 10px; / when horizontal */ } centralWidget:hover { background: red; }
    • UNSOLVED Can we use CSS on QPushButton
      General and Desktop • stylesheet qt 5.7 css • • Swapnil_Shelke  

      6
      0
      Votes
      6
      Posts
      7189
      Views

      @Swapnil_Shelke To create those kind of buttons you need more than CSS. You must go into button's paintEvent and then draw what you need (there are 3 simultaneous animation BTW) : #include <QtCore/qvariantanimation.h> #include <QtCore/qvariant.h> #include <QtWidgets/qabstractbutton.h> #include <QtWidgets/qapplication.h> #include <QtWidgets/qlayout.h> class Animation : public QVariantAnimation { Q_OBJECT public: Animation(QObject *parent = 0) :QVariantAnimation(parent) { setTargetWidget(qobject_cast<QWidget*>(parent)); setAutoUpdateEnable(true); } void setAutoUpdateEnable(bool a) { if (targetWidget()) { a ? QObject::connect(this, SIGNAL(valueChanged(QVariant)), targetWidget(), SLOT(update())) : QObject::disconnect(this, SIGNAL(valueChanged(QVariant)), targetWidget(), SLOT(update())); } } QWidget *targetWidget() const { return _target; } void setTargetWidget(QWidget *w) { _target = w; } QVariant value() const { return _value; } void setValue(const QVariant &variant) { if (_value == variant) return; _value = variant; } protected: void updateCurrentValue(const QVariant &value) override { setValue(value); } private: QVariant _value; QWidget *_target = nullptr; }; class SampleButton :public QAbstractButton { public: struct ButtonStyle { qreal border_radius = 4.0; QColor background_color = QColor("#f4511e"); QColor text_color = QColor("#ffffff"); int font_size = 28; QString font_family = "Arial"; int width = 200; int padding = 20; qreal hover_padding = 25; int duration = 600; QIcon icon = QIcon("next.png"); // http://www.flaticon.com/free-icon/double-angle-pointing-to-right_25358 @16x16 qreal pixmap_padding = 20; }; SampleButton(const QString &text, QWidget *parent = 0) :QAbstractButton(parent), _textEff(new Animation(this)), _pixmapEff0(new Animation(this)), _pixmapEff1(new Animation(this)) { setFont(QFont(_st.font_family, _st.font_size)); setText(text); } QSize sizeHint() const override { return QSize(_st.width, _st.padding + fontMetrics().height() + _st.padding); } protected: void paintEvent(QPaintEvent *) override { QPainter p(this); // draw background p.setPen(Qt::NoPen); p.setBrush(_st.background_color); p.setRenderHint(QPainter::Antialiasing, true); p.drawRoundedRect(rect(), _st.border_radius, _st.border_radius); p.setRenderHint(QPainter::Antialiasing, false); // draw text if (!text().isEmpty()) { p.setFont(font()); p.setPen(_st.text_color); p.setRenderHint(QPainter::TextAntialiasing, true); p.drawText(QRectF(rect().x() - _textEff->value().toReal(), rect().y(), rect().width(), rect().height()), Qt::AlignCenter, text()); p.setRenderHint(QPainter::TextAntialiasing, false); } // draw icon if (!_st.icon.isNull()) { p.setRenderHint(QPainter::SmoothPixmapTransform, true); auto s = _st.icon.availableSizes().at(0); p.setOpacity(_pixmapEff0->value().toReal()); p.drawPixmap(QPointF(rect().right() - (_st.pixmap_padding * 2) - _pixmapEff1->value().toReal(), rect().center().y() - s.width() / 4), _st.icon.pixmap(s)); } } void enterEvent(QEvent *e) { _textEff->setStartValue(0.0); _textEff->setEndValue(_st.hover_padding); _textEff->setDuration(_st.duration); _textEff->setEasingCurve(QEasingCurve::OutCubic); _textEff->start(); _pixmapEff0->setStartValue(0.0); _pixmapEff0->setEndValue(1.0); _pixmapEff0->setDuration(_st.duration); _pixmapEff0->setEasingCurve(_textEff->easingCurve()); _pixmapEff0->start(); _pixmapEff1->setStartValue(0.0); _pixmapEff1->setEndValue(_st.pixmap_padding); _pixmapEff1->setDuration(_st.duration); _pixmapEff1->setEasingCurve(_textEff->easingCurve()); _pixmapEff1->start(); QWidget::enterEvent(e); } void leaveEvent(QEvent *e) { _textEff->setStartValue(_st.hover_padding); _textEff->setEndValue(0.0); _textEff->setDuration(_st.duration); _textEff->start(); _pixmapEff0->setStartValue(1.0); _pixmapEff0->setEndValue(0.0); _pixmapEff0->setDuration(_st.duration); _pixmapEff0->start(); _pixmapEff1->setStartValue(_st.pixmap_padding); _pixmapEff1->setEndValue(0.0); _pixmapEff1->setDuration(_st.duration); _pixmapEff1->setEasingCurve(_textEff->easingCurve()); _pixmapEff1->start(); QWidget::leaveEvent(e); } private: ButtonStyle _st; Animation *_textEff = nullptr; Animation *_pixmapEff0 = nullptr; Animation *_pixmapEff1 = nullptr; }; int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *dialog = new QWidget; dialog->setWindowFlags(Qt::FramelessWindowHint); QHBoxLayout _Layout; dialog->setLayout(&_Layout); SampleButton *sb = new SampleButton("Hover"); _Layout.addWidget(sb); dialog->show(); return app.exec(); } #include "main.moc"