Quickly, you can create a custom widget that inherits QLineEdit.
Then have a QHBoxLayout inside with all those components, something like this:
magnifierIcon->setFocusPolicy(Qt::NoFocus);
magnifierIcon->setObjectName("searchMagnifierIcon");
magnifierIcon->setPixmap("qrc:/images/magnifier.png");
voiceInput->setObjectName("voiceInputIcon");
voiceInput->setPixmap("qrc:/images/voiceinput.png");
lineEditLayout->setMargin(0);
lineEditLayout->addWidget(magnifierIcon, 0, Qt::AlignLeft|Qt::AlignVCenter);
lineEditLayout->addStretch();
lineEditLayout->addWidget(voiceInput, 0, Qt::AlignRight|Qt::AlignVCenter);
// Set the QLineEdit layout
setLayout(lineEditLayout);
QLabel magnifierIcon = new QLabel(this);
magnifierIcon->setFocusPolicy(Qt::NoFocus);
magnifierIcon->setObjectName("searchMagnifierIcon");
magnifierIcon->setPixmap("qrc:/images/magnifier.png");
QLabel voiceInput = new QLabel(this);
voiceInput->setObjectName("voiceInputIcon");
voiceInput->setPixmap("qrc:/images/voiceinput.png");
QHBoxLayout *lineEditLayout = new QHBoxLayout;
lineEditLayout->setMargin(0);
lineEditLayout->addWidget(magnifierIcon, 0, Qt::AlignLeft|Qt::AlignVCenter);
lineEditLayout->addStretch();
lineEditLayout->addWidget(voiceInput, 0, Qt::AlignRight|Qt::AlignVCenter);
// Set the QLineEdit layout
setLayout(lineEditLayout);
To copy to clipboard, switch view to plain text mode
Ofcourse the magnifierIcon could be a QComboBox or a QToolButton.
Then your stylesheet would be something like this:
{
border: 1px solid #D2D2D2;
padding-left: 15px; /* must have padding on the left, so it gives some space for the magnifier icon */
padding-right: 15px; /* must have padding on the right, so it gives some space for the voice input icon */
border-radius: 8px;
}
{
border: 0px;
padding: 0px;
width: 13px; /* width of the magnifier icon */
height: 12px; /* height of the magnifier icon */
margin-left: 5px;
}
QLineEdit
{
border: 1px solid #D2D2D2;
padding-left: 15px; /* must have padding on the left, so it gives some space for the magnifier icon */
padding-right: 15px; /* must have padding on the right, so it gives some space for the voice input icon */
border-radius: 8px;
}
QLineEdit #searchMagnifierIcon
{
border: 0px;
padding: 0px;
width: 13px; /* width of the magnifier icon */
height: 12px; /* height of the magnifier icon */
margin-left: 5px;
}
To copy to clipboard, switch view to plain text mode
I hope this helps.
Bookmarks