Setting CSS style through web pages and QWidgets

  • Hi everyone,

    I'm creating a Qt application with some web pages loaded on QWebViews and also some plain QWidgets, all inside a QMainWindow. Both the webpages and widgets are going to have some checkboxes here and there, and I'd like them to look the same. Well, at first they DO look the same, because they inherit their style from the native theme engine, but I'd like to define a new CSS style for both.

    I tried some things like

    @QCheckBox::indicator:unchecked {
    image: url(:/image/checkbox_unchecked.png);

    but that only works for checkboxes inside my QWidgets.

    I also tried some plain CSS style, but then they only apply to webpage checkboxes.

    So, is there a way I could design a single CSS style for checkboxes and apply it to all sorts of checkboxes inside my application?

    For the record, I could achieve that when it comes to text selection. I set the main window stylesheet to

    @selection-color: #363636; selection-background-color: #bfebeb;@

    and both web page and qwidget selections followed this style.

  • Well you should apply qss and plain css... You cannot apply just one for both... At least not that I know of...

  • check out

    you will need something along the lines of this

    ui->checkBox->setStyleSheet("QCheckBox{ spacing: 10 }\n"
                                "QCheckBox::indicator:checked:hover{image: url(:/images/checkbox_checked_hover.png);}\n"
                                "QCheckBox::indicator:checked:pressed{image: url(:/images/checkbox_checked_pressed.png);}");

  • @Thuthuka he said he managed to set stylesheet for QCheckbox... His problem is how to set one CSS code for both QCheckBox and the Web CheckBoxes...

  • Exactly. I thought it was possible since I achieved that for text selection, using

    selection-color: #363636; selection-background-color: #bfebeb;

    as I said before.


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.