PDA

View Full Version : custom combobox



premroxx
6th December 2012, 06:13
I'm having some trouble customizing a dynamic combobox. my current style is as follows

QCheckBox *checkbox = new QCheckBox(QString(query.value(2).toString()),this) ;
checkbox->setStyleSheet("font: MS Shell Dlg 2; font-size: 40px; color: white;");
checkbox->setCheckable(false);
checkbox->setIconSize(QSize(60,60));
checkbox->setIcon(QIcon(":/images/Circles1.png"));

Now the issue is, i get a checkmark box next to the icon. but I want the Icon "instead of the checkmark box". How do I do that. I've seen examples of indicators. but they only seem to work if you manually set the stylesheet in qt designer

ChrisW67
7th December 2012, 22:23
You do this by styling the QCheckBox::indicator sub-control.

The style sheet in you example above is malformed, which may explain why you cannot make it work outside Designer. You should quote the font name to avoid any possible confusion caused by the space and you should either specify the size and name together with font: or use font-family: and font-size: to set them separately.


QCheckBox cb("Test Check box");
// This
cb.setStyleSheet("font: 36pt 'Comic Sans MS';");
// or this
cb.setStyleSheet("font-size: 36pt; font-family: 'Comic Sans MS';");

// Styling indicator
cb.setStyleSheet(
"QCheckBox {font-size: 36pt; font-family: 'Comic Sans MS'; }"
"QCheckBox::indicator { width: 32px; height: 32px; }"
"QCheckBox::indicator:unchecked { image: url(checkbox_unchecked.png); } "
"QCheckBox::indicator:checked { image: url(checkbox_checked.png); } "
);
cb.show();

premroxx
17th December 2012, 10:26
QCheckBox *checkbox = new QCheckBox(QString(query.value(2).toString()),this) ;
checkbox->setStyleSheet(
"QCheckBox {font-size: 20pt; font-family: 'MS Shell Dlg 2'; color: white;}"
"QCheckBox::indicator:unchecked { image: url(/images/Circles1.png); } "
"QCheckBox::indicator:checked { image: url(/images/Circles.png); } "
);
checkbox->show();

I tried it, but now it doesnt even show the checkbox image, just the test

premroxx
18th December 2012, 01:21
Fixed. Thank You.