Skip to content
  • 0 Votes
    1 Posts
    268 Views
    No one has replied
  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    Sorry for the very late reply, would it be possible to have a complete minimal compilable project to be able to test your issue ?

  • 0 Votes
    1 Posts
    316 Views
    No one has replied
  • 0 Votes
    4 Posts
    909 Views
    SGaistS

    It's likely something that is highly specific to your device.
    What is it running to manage its GUI ?

  • 0 Votes
    7 Posts
    815 Views
    D

    I finally got it solved...

    The fix was:

    QPushButton { width: 100%; }

    :- )

  • 0 Votes
    5 Posts
    1k Views
    SGaistS

    You can read the class sources.

  • 0 Votes
    3 Posts
    891 Views
    mrjjM

    @mikael-larsson
    Hi
    You could try an event filter on the Combobox and call the code for hover effect but
    if your effect is purely stylesheet based then i think you then must send it fake hover event to trigger it or something like that.

    You might also be able to subclass the combo and rig the paintEvent with
    if (someflag)
    option.state |= QStyle::State_MouseOver;

    to trigger hover on command from the event filter/ or combo hover or how you plan to trigger it.

  • 0 Votes
    6 Posts
    3k Views
    N

    This is what I've done right now.
    Using the same code for painting and widget, I'm able to use a custom widget as usual; moreover, for listview I'm able to render the same widget correctly (because calling render method of widget, the widget is able to read .qss stylesheet)

    Here is the example:

    this is a single widget
    0_1562332451778_widget.png

    and this is the rendered widget inside the listview
    0_1562332527764_listview-render.png

    in listview, as you can see, I'm able to render widget correctly and, in case of focus, I can change focus style using a custom property

    this is the code:

    void AlertItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QVariant data = index.data(); if (data.canConvert<Error>()) { auto&& styleOption = QStyleOptionViewItem(option); ErrorItemWidget widget; if (styleOption.state & QStyle::State_HasFocus) widget.setProperty("Test", true); // <-- custom focus property else widget.setProperty("Test", QVariant::Invalid); // <-- remove property for normal state widget.resize(option.rect.width(), option.rect.height()); widget.setError(qvariant_cast<Error>(data)); painter->save(); painter->translate(option.rect.topLeft()); widget.render(painter); painter->restore(); } else { QStyledItemDelegate::paint(painter, option, index); } }

    The drawback of this solution is that I need to create a widget for each model item (however, I've render 2000 elements and I don't see any performance hit)
    The other drawback is that the height of each item is hardly code inside size-hint method, that is:

    QSize AlertItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { int width = option.rect.width(); int height = 48; // <--- if I can get this from stylesheet, I'll be happy :) return QSize(width, height); }

    The good thing is that I can change widget stylesheet using .qss file; inside C++ code there isn't any style detail.

    Any suggestion to get height value from stylesheet?

    Thanks all!
    Nicola

  • 0 Votes
    8 Posts
    2k Views
    JonBJ

    @b2soft

    I want to customize BrowserModel ::data() returning colors using QSS

    @raven-worx knows much more than I, but I don't get this. role == Qt::TextColorRole will want to return a QBrush (http://doc.qt.io/qt-5/qt.html#ItemDataRole-enum). How is that linked to returning a string to use for a name in a stylesheet? :confused:

  • 1 Votes
    10 Posts
    4k Views
    O
    QListView {outline: none;}
  • 0 Votes
    4 Posts
    1k Views
    A

    Ok,
    I found the bullshit. My first try was setStyleSheet("background-color: myColor;"). As it did not work (no border when checked), I tried after setStyleSheet("QToolButton {background-color: myColor;}"). As it was still the same shit, and as the documentation recommends to set the border, I have moved to setStyleSheet("QToolButton {background-color: myColor; border:none;}") (as in the QSS file). And all the following tries were with "border:none" on the rule without the :checked modifier.

    Suprisingly, without the definition of the border in the setStyleSheet everything works well. So I have the border defined in the QSS file (as from the beginning). And in the program I have:

    currentBtn ->setStyleSheet(QString("QToolButton#BooleanObject {background-color: %1;} QToolButton#BooleanObject:checked {background-color:%1;}").arg(myColor.name()));

    This is a really strange behavior. But, long time ago, I have understood that I will never understand the "logic" of the QT style sheet.

  • Get margins of QPushButton

    Solved General and Desktop
    13
    1 Votes
    13 Posts
    11k Views
    C

    @goldstar2154 Totally agree with you - there is a obvious bug. But thanks to @raven-worx 's code we've got a way to get a result at least. And "solved" will help in web search:)
    Thank you very much for this question:)

  • 0 Votes
    2 Posts
    738 Views
    dheerendraD

    Widget style sheet has precedence over qapplication style sheet. Hence u r seeing this issue

  • 0 Votes
    9 Posts
    5k Views
    mrjjM

    @Romain-C
    Well it still confused me sometimes :)

  • 0 Votes
    14 Posts
    3k Views
    IMAN4KI

    @raven-worx
    Oh..
    Sorry i think that was qt-bug (getter return invalid) but now it's work

    For last question !
    Could i use qcssparser_p.h for retrieving values for my purpose ? (i'm a lover of parsing :) )
    Thanks.

  • 0 Votes
    5 Posts
    2k Views
    mongrelmacM

    I see. Thanks @raven-worx @SGaist!

  • 0 Votes
    15 Posts
    5k Views
    V

    @mrjj @Ratzz Thank u guys alot for helping me fix this prob.

  • 0 Votes
    4 Posts
    3k Views
    raven-worxR

    @LoPiTaL
    you could still combine both styles in one CSS. You just need to adapt your selectors.
    E.g. you could set an property to your widgets and only apply certain styles to them.

  • 0 Votes
    3 Posts
    4k Views
    raven-worxR

    @ericg22
    You can simply set properties of widgets via QSS. Most basic types are parsed. Even enums can be used by name when registered to the meta system.

    class MyWidget : public QWidget { Q_OBJECT Q_PROPERTY( QColor CustomColor READ ... WRITE ... DESIGNABLE true ) Q_RPOPERTY( QFont CustomFont READ ... WRITE ... DESIGNABLE true ) Q_PROPERTY( QString CustomString READ ... WRITE ... DESIGNABLE true ) Q_PROPERTY( int CustomInteger READ ... WRITE ... DESIGNABLE true ) Q_PROPERTY( QIcon CustomIcon READ ... WRITE ... DESIGNABLE true ) Q_PROPERTY( MyEnum CustomEnum READ ... WRITE ... DESIGNABLE true ) Q_ENUMS( MyEnum ) ... enum MyEnum { MyEnumValue1, MyEnumValue2 } }

    example qss to set properties:

    MyWidget { qpropert-CustomColor: rgba(...); //also rgb(), hsv(), rgba(), named-colors, #XXXXXX, etc. are possible9 qproperty-CustomFont: "serif,-1,14,5,0,0,0,0,0,0"; // see QFont::fromString(): Font-Family, pointSizeF, pixelSize, QFont::StyleHint, QFont::Weight, QFont::STyle, underline, strikeout, fixedPitch, rawMode qproperty-CustomFont: "Times New Roman,12"; //should also be possible qproperty-CustomString: "Any string..."; qproperty-CustomInt: 8253; qproperty-CustomIcon: url(:/path/to/qrc/resource/icon.png); qproperty-CustomEnum: MyEnumValue2; }