C++ (Qt)ButtonLineEdit::ButtonLineEdit(const QString &text, QWidget *parent): QLineEdit(text, parent), buttonBox(new QWidget(this)), button1(new QToolButton(buttonBox)), button2(new QToolButton(buttonBox)){ buttonBox->setCursor(Qt::ArrowCursor); const QString buttonStyle = "QToolButton {"\ "border: none;"\ "padding: 0px;}"\ "QToolButton:hover {"\ "border-left: 1px solid lightgray;"\ "border-right: 1px solid lightgray;}"; button1->setIcon(QIcon(":/images/tick.png")); button1->setStyleSheet(buttonStyle); button2->setIcon(QIcon(":/images/cross.png")); button2->setStyleSheet(buttonStyle); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); QLayout *layout = new QHBoxLayout(buttonBox); layout->setSpacing(1); layout->setContentsMargins(0, 0, frameWidth, 0); layout->addWidget(button1); layout->addWidget(button2); setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(buttonBox->sizeHint().width() + frameWidth));}
C++ (Qt)QPalette pal = palette();pal.setColor(backgroundRole(), Qt::red);setPalette(pal);
C++ (Qt)setStyleSheet("QLineEdit {background-color: red;}");
C++ (Qt)ButtonLineEdit *edit = new ButtonLineEdit(combo);edit->setStyleSheet("QLineEdit {background-color: red;}");combo->setLineEdit(edit);
C++ (Qt)ButtonLineEdit::ButtonLineEdit(const QString &text, QWidget *parent): QLineEdit(text, parent), buttonBox(new QWidget(this)), button1(new QToolButton(buttonBox)), button2(new QToolButton(buttonBox)){//1setStyleSheet("background-color: red;"); ...//2setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(buttonBox->sizeHint().width() + frameWidth));}