qt - QComboBox style for choosed item in drop-down list -
i want style highlightation of choosed item in drop-down of combobox.
the difference other questions not want style "selected" item(hovered mouse) .. but interested in styling choosed item.
the default sort of ticker painted on text. want choosed item have bold text , no ticker image.
or in worst case shifth text right make ticker visible properly.
what have this:
notice 17th item has ticker on number 17.
this stylesheet:
qcombobox { subcontrol-origin: padding; subcontrol-position: top right; selection-background-color: #111; selection-color: yellow; color: white; background-color: qlineargradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #565656, stop: 0.1 #525252, stop: 0.5 #4e4e4e, stop: 0.9 #4a4a4a, stop: 1 #464646); border-style: solid; border: 1px solid #1e1e1e; border-radius: 5; padding: 1px 0px 1px 20px; } qcombobox:hover, qpushbutton:hover { border: 1px solid yellow; color: white; } qcombobox:editable { background: red; color: pink; } qcombobox:on { padding-top: 0px; padding-left: 0px; color: white; background-color: qlineargradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #2d2d2d, stop: 0.1 #2b2b2b, stop: 0.5 #292929, stop: 0.9 #282828, stop: 1 #252525); selection-background-color: #ffaa00; } qcombobox:!on { color: white; background-color: qlineargradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #666, stop: 0.1 #555, stop: 0.5 #555, stop: 0.9 #444, stop: 1 #333); } qcombobox qabstractitemview { border: 2px solid darkgray; color: black; selection-background-color: qlineargradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #111, stop: 1 #333); } qcombobox::drop-down { subcontrol-origin: padding; subcontrol-position: top right; width: 15px; color: white; border-left-width: 0px; border-left-color: darkgray; border-left-style: solid; /* single line */ border-top-right-radius: 3px; /* same radius qcombobox */ border-bottom-right-radius: 3px; padding-left: 10px; } qcombobox::down-arrow, qspinbox::down-arrow, qtimeedit::down-arrow, qdateedit::down-arrow { image: url(:/icons/down_arrow.png); width: 7px; height: 5px; }
i trying override item delagate:
ui->modecombobox->setitemdelegate(new qstyleditemdelegate());
along with
qcombobox qabstractitemview::item:selected style
or override view:
qlistview * listview = new qlistview(ui->modecombobox); listview->setstylesheet("qlistview::item { \ border-bottom: 5px solid white; margin:3px; } \ qlistview::item:selected { \ border-bottom: 5px solid black; margin:3px; \ color: black; \ }"); ui->modecombobox->setview(listview);
but in both cases totally disables highlight of choosed item (which 17th item)
update 1
i tested set ::item:checked stylesheet didnt helped:
qlistview * listview = new qlistview(ui->modecombobox); listview->setstylesheet("qlistview::item { \ border-bottom: 5px solid white; margin:3px; } \ qlistview::item:selected { \ border-bottom: 5px solid black; margin:3px; \ color: black; } \ qlistview::item:checked { \ background-color: green; \ color: green;}" ); ui->modecombobox->setview(listview);
also added stylesheet sure:
qcombobox qlistview::item:checked { background-color: green; }
the result 17 mode checked (the black mouse hover):
update 2
ok able change weight of font of checked item, cannot remove stupid ticker item.. experimented stylesheet file , found out these 2 selectors responsible style of checked items highlightation:
qwidget:item:selected { border: 0px solid #999900; background: transparent; } qwidget:item:checked { font-weight: bold; }
if remove ::item:selected ::item:checked not work (it not bolderise checked item) , ticker dissappears.
on qt forum advised somehow shortened "space icons of combobox".. cannot find selector responsible that..
i have feeling style sheet black magic , choosed can understand happening inside..
ok after lot of struggle made workaround.. not best, not proper, looks ok..
i added bold effect in way (it affect other widgets checkable menu items, can live that):
qwidget:item:selected { border: 0px solid #999900; background: transparent; } qwidget:item:checked { font-weight: bold; }
then when adding items prepending spaces text in order shift right.. trying many things, nothing affected qabstractitemview inside.
this result:
Comments
Post a Comment