Tiffany
Tiffany

Reputation: 45

Change QCheckBox Style in Qt Jambi

I am currently using Eclipse 3.5.2 and Qt Jambi 4.7.2 in Ubuntu 11.04 Natty Narwhal

I am trying to use stylesheets to customize my QCheckBox. I have found examples for C++ but I cannot find equivalents for Java. I am wanting to do something similar to the following using stylesheets.

QCheckBox::indicator {
    width: 13px;
    height: 13px;
}

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

QCheckBox::indicator:unchecked:hover {
    image: url(:/images/checkbox_unchecked_hover.png);
}

QCheckBox::indicator:unchecked:pressed {
    image: url(:/images/checkbox_unchecked_pressed.png);
}

QCheckBox::indicator:checked {
    image: url(:/images/checkbox_checked.png);
}

QCheckBox::indicator:checked:hover {
    image: url(:/images/checkbox_checked_hover.png);
}

QCheckBox::indicator:checked:pressed {
    image: url(:/images/checkbox_checked_pressed.png);
}

If anyone could help me out, it would be much appreciated. Thanks in advance!

Also, does anyone know how to make a QCheckBox bigger?

Upvotes: 1

Views: 626

Answers (2)

Tiffany
Tiffany

Reputation: 45

In order to change the size of the check box you can use

QCheckBox::indicator {
    width: 50px;
    height: 50px;
}

in your style sheet. This makes the check mark very pixelated however so I then proceeded to use

QCheckkBox::indicator:checked {
   border-image: url(classpath:Icons/checkmark.png);
}

along with the first thing. It works wonderfully and the checkmark can be any image you want to use!

Upvotes: 0

Smar
Smar

Reputation: 8591

Judging this page, you can set stylesheets into use with QApplication::setStyleSheet() and QWidget::setStyleSheet(). Neither of those is static function, so something like

MyWidget widget = new MyWidget();
widget.setStyleSheet("path/to/stylesheet");

Note that I haven’t myself tried those stylesheets, as a developer of Jambi I’d be interested if those styleheets actually work and if they could be fixed then.

EDIT: And for making check boxes bigger, maybe easiest way is to wrap them into layouts and let layouts to populate whole widget size -> with one item in a layout the widget in layout would be as big as the widget where the layout is attached to.

Upvotes: 1

Related Questions