Zmienianie koloru QPushButtona [Qt]

0

Witam. Chciałbym zmienić kolor QPushButtona. Próbowałem to zrobić przy pomocy StyleSheeta,

button->setStyleSheet("background-color: yellow");

ale zmieniony kolor był jednolity. Chodzi mi o to, żeby zachować ogólne "cieniowanie" przycisku. Da się to zrobić bez wczytywania do programu grafik?

0

Musiałbyś odtworzyć w tym zmodyfikowanym css wygląd zwykłego przycisku i go wtedy modyfikować. Zmiana stylu jak w twoim przypadku kasuje domyślny systemowy wygląd kontrolek.

0

Tyle zdążyłem się domyślić, ale nie mogę nigdzie znaleźć, jak dokładnie to zrobić.

0

Możesz użyć tego:
http://qt-project.org/doc/qt-4.8/qwidget.html#setGraphicsEffect

Gdzieś kiedyś czytałem o użyciu QGradient razem z kutekowym CSS ale nie widziałem kodu takiej kombinacji.

2

w designerze klikasz prawym na push button -> edit style sheet

i wklejasz np

QPushButton {
    /* Let's make the size of the button 1,5 times of font size. */
    min-height: 1.5em;
    /* Font size just 1.*/
    font: 1em;
    /* Margins so that we get a little space on the left and right. */
    margin: 0 1px 0 1px;
    /* The font color */ 
    color: white;
    /* Here's the background gradient with start point, end point, 
       stop "percentage" and color, stop percentage and color. */
    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #2198c0, stop: 1 #0d5ca6);
    /* We'll round the borders. */
    border-style: outset;
    /* Round radius will be 3px */
    border-radius: 3px;
    /* Border is only one pixel */
    border-width: 1px;
    /* Border color is now set */
    border-color: #0c457e;
}
 
/* This is style when button is pressed */
QPushButton:pressed {
    /* We'll just invert the gradient by changing the colors around. */
    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #0d5ca6, stop: 1 #2198c0);
}

efekt niesamowity, sam to 1 raz wypróbowałem

wiedza zaczerpnięta -> http://developer.nokia.com/community/wiki/Archived:Creating_a_gradient_background_for_a_QPushButton_with_style_sheet

user image

1 użytkowników online, w tym zalogowanych: 0, gości: 1