Results 1 to 4 of 4

Thread: custom combobox

  1. #1
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default custom combobox

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: custom combobox

    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.
    Qt Code:
    1. QCheckBox cb("Test Check box");
    2. // This
    3. cb.setStyleSheet("font: 36pt 'Comic Sans MS';");
    4. // or this
    5. cb.setStyleSheet("font-size: 36pt; font-family: 'Comic Sans MS';");
    6.  
    7. // Styling indicator
    8. cb.setStyleSheet(
    9. "QCheckBox {font-size: 36pt; font-family: 'Comic Sans MS'; }"
    10. "QCheckBox::indicator { width: 32px; height: 32px; }"
    11. "QCheckBox::indicator:unchecked { image: url(checkbox_unchecked.png); } "
    12. "QCheckBox::indicator:checked { image: url(checkbox_checked.png); } "
    13. );
    14. cb.show();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: custom combobox

    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

  4. #4
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: custom combobox

    Fixed. Thank You.

Similar Threads

  1. Custom QHeaderView with multiple header rows and comboBox
    By alizadeh91 in forum Qt Programming
    Replies: 2
    Last Post: 26th November 2012, 22:03
  2. Custom Combobox
    By zgulser in forum Qt Programming
    Replies: 20
    Last Post: 4th April 2012, 10:13
  3. How to make Custom Combobox ?
    By qt_man in forum Newbie
    Replies: 4
    Last Post: 15th February 2012, 05:01
  4. How to set custom height for ListView & ComboBox items
    By rawfool in forum Qt Programming
    Replies: 1
    Last Post: 30th September 2011, 10:39
  5. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 20:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.