16,235
社区成员
发帖
与我相关
我的任务
分享
ui->comboBox->setStyleSheet("QComboBox::drop-down:pressed"
"{"
"subcontrol-position:center right;"//按钮位置
"image:url(:/2.png);"//按钮图片
"}"
"QComboBox:drop-down"
"{"
"subcontrol-position:center right;"//
"image:url(:/1.png);"//
"}"
"QComboBox:drop-down:hover"
"{"
"subcontrol-position:center right;"
"image:url(:/2.png);"
"}"
"QComboBox"
"{"
"color: rgb(255, 0, 0);"
"border-width: 2px;"
"border-style: solid;"
"border-color: rgb(0,0,0);"
"}"
"QComboBox::background"
"{"
"border:1px solid #000000;"
"padding:1px 18px 1px 3px;"
"min-width:100px;"
"font:12px;"
"}"
"QComboBox:!editable,QComboBox::drop-down:editable "
"{"
"background:qlineargradient(x1:0, y1:0, x2:1, y2:0,"
"stop:0 rgb(0,0,0), stop:1 rgb(0,0,0));"
"}"
"QComboBox QAbstractItemView "
"{"
"border: 1px solid rgb(0, 0, 0);"
"background: rgb(0, 0, 0);"
"outline: none;"
"}"
"QComboBox QAbstractItemView::item "
"{"
"height: 25px;"
"color: rgb(0, 255, 0);"
"}"
"QComboBox QAbstractItemView::item:selected "
"{"
"background: rgb(73, 73, 73);"
"color: rgb(0, 0, 255);"
"}"
);
QComboBox *cm = new QComboBox(this);
cm->addItem("1");
cm->addItem("2");
cm->setEditable(true);
cm->setCurrentIndex(0);
cm->setGeometry(0, 0, 240, 40);
cm->setStyleSheet("QComboBox {background:green;}");
cm->setInsertPolicy(QComboBox::InsertAtCurrent);
背景的话 直接改QComboBox就有效果ui->comboBox->setItemText(ui->comboBox->currentIndex(), text);