Qt Designer StyleSheet. Как поменять обводку выбранного элемента из QComboBox
Этот код меняет background объектов в combobox при наведении
QComboBox QListView {
selection-background-color: rgb(255, 255, 255);
}
test.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="styleSheet">
<string notr="true">
/* вот этот код работает */
QComboBox QListView {
background-color:rgb(52, 58, 64);
selection-background-color:white;
}
/* а вот этот нет */
QComboBox QListView::item:hover{
border:1px;
border-color: rgb(170, 85, 127);
}</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QComboBox" name="comboBox">
<property name="geometry">
<rect>
<x>250</x>
<y>110</y>
<width>69</width>
<height>22</height>
</rect>
</property>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
а мне нужно поменять border объектов в combobox
Я добавляю StyleSheet через Qt Designer. Не могу найти как поменять параметры item comboBox.
Ответы (1 шт):
Автор решения: S. Nick
→ Ссылка
Попробуйте так:
QComboBox {
font: 18pt Fira Sans Condensed;
background-color: #2e2e2e;
border-top: 0px solid #3e3e3e;
border-left: 0px solid #3e3e3e;
border-right: 0px solid #3e3e3e;
border-bottom: 2px solid #3e3e3e;
padding: 5%;
max-height: 30px;
min-width: 140px;
color: white;
selection-background-color: #5e5e5e;
}
QComboBox::drop-down {
border: none;
}
QComboBox::down-arrow {
image: url(down-arrow.png);
width: 25px;
height: 25px;
border-width: 0px;
padding-right: 10px;
}
QComboBox::down-arrow:pressed {
position: relative;
top: 1px; left: 1px;
}
QComboBox QListView {
background-color: #2e2e2e;
/* outline: 0; попробуйте так */
outline: 2px solid red; /* или так */
color: white;
selection-background-color: #5e5e5e;
padding: 5%;
}
q1408477_test.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>440</width>
<height>448</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="styleSheet">
<string notr="true">QWidget {
background-color: #18465d;
}
QComboBox {
font: 18pt Fira Sans Condensed;
background-color: #2e2e2e;
border-top: 0px solid #3e3e3e;
border-left: 0px solid #3e3e3e;
border-right: 0px solid #3e3e3e;
border-bottom: 2px solid #3e3e3e;
padding: 5%;
max-height: 30px;
min-width: 140px;
color: white;
selection-background-color: #5e5e5e;
}
QComboBox::drop-down {
border: none;
}
QComboBox::down-arrow {
image: url(down-arrow.png);
width: 25px;
height: 25px;
border-width: 0px;
padding-right: 10px;
}
QComboBox::down-arrow:pressed {
position: relative;
top: 1px; left: 1px;
}
QComboBox QListView {
background-color: #2e2e2e;
/* outline: 0; попробуйте так */
outline: 2px solid red; /* или так */
color: white;
selection-background-color: #5e5e5e;
padding: 5%;
}</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QComboBox" name="comboBox">
<property name="geometry">
<rect>
<x>70</x>
<y>70</y>
<width>261</width>
<height>42</height>
</rect>
</property>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>440</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
down-arrow.png


