Anton1978
Anton1978

Reputation: 35

How to change frame style using QSS?

Good day. There is an instruction on frame styles, here https://doc.qt.io/qt-5/qframe.html#setFrameStyle

Suppose I want my button to have the Box | Sunken. How can I do this using QSS? I tried to do it like this:

frameStyle: box;
background-color: rgb (230, 230, 230);
border: 1px solid white;
border-right: 2px solid rgb (127, 127, 127);
border-bottom: 2px solid rgb (127, 127, 127);

But it didn’t help, apparently I just don’t know any word of the code.

Upvotes: 1

Views: 2077

Answers (1)

Baxtrax
Baxtrax

Reputation: 75

If QSS is what you are looking for then I would recommend looking at the stylesheet reference and stylesheet examples in the documentation. It has helped me countless times when trying to figuring out how to style something with QSS.

Your style sheet should be enclosed in curly brackets as follows:

QFrame {
    background-color: rgb (230, 230, 230);
    border: 1px solid white;
    border-right: 2px solid rgb (127, 127, 127);
    border-bottom: 2px solid rgb (127, 127, 127);
}

If you are trying to style a button I would recommend doing something as follows though. There are more examples on the stylesheet reference and examples mentioned earlier.

This is ripped right from the QSS examples documentation under QPushButton

QPushButton {
    border: 2px solid #8f8f91;
    border-radius: 6px;
    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #f6f7fa, stop: 1 #dadbde);
    min-width: 80px;
}

QPushButton:pressed {
    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #dadbde, stop: 1 #f6f7fa);
}

QPushButton:flat {
    border: none; /* no border for a flat push button */
}

QPushButton:default {
    border-color: navy; /* make the default button prominent */
}

Using QSS in this way will allow you to make changes to how the button looks in its different states, etc.

Upvotes: 1

Related Questions