How to insert QProgressIndicator into QLineEdit?
-
I'm trying to insert "QProgressIndicator":http://qt-apps.org/content/show.php/QProgressIndicator?content=115762 into QLineEdit, but for now I only find right padding, but not a height (for all OS).
@LineEdit::LineEdit(QWidget *parent) :
QLineEdit(parent)
{
progressIndicator = new ProgressIndicator(this);QStyleOptionFrameV2 panel; initStyleOption(&panel); QRect rect = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); qDebug()<<rect; progressIndicator->setFixedSize(rect.height(),rect.height()); progressIndicator->move(rect.x(), rect.y()); setStyleSheet(QString("padding-left: %1px;").arg(progressIndicator->width()));
}
void LineEdit::initStyleOption(QStyleOptionFrameV2 *option) const
{
option->initFrom(this);
option->rect = contentsRect();
option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this);
option->midLineWidth = 0;
option->state |= QStyle::State_Sunken;
if (this->isReadOnly())
option->state |= QStyle::State_ReadOnly;
#ifdef QT_KEYPAD_NAVIGATION
if (hasEditFocus())
option->state |= QStyle::State_HasEditFocus;
#endif
option->features = QStyleOptionFrameV2::None;
}@On KDE
!http://storage4.static.itmages.ru/i/12/0317/h_1332011786_9895714_4b67f50564.png(KDE)!On Windows7
!http://storage6.static.itmages.ru/i/12/0317/h_1332011823_4977120_0906f246cf.png(Win7)! -
Would it help if you moved your code from the constructor to the resizeEvent? That's where I usually do this kind of tricks. There you can be sure you get the correct size information from the widget.
-
Thanks! It helps.
But now,
@setStyleSheet(QString("padding-left: %1px;").arg(progressIndicator->width()));@
move progressIndicator to left too.
Can I set padding only for text? -
Could you show the code you now have, please?
You should of course still position the indicator manually inside the resizeEvent implementation. -
@void LineEdit::resizeEvent(QResizeEvent *)
{
QStyleOptionFrameV2 panel;
initStyleOption(&panel); // the save as in the first post
QRect rect = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
progressIndicator->setFixedSize(rect.height(), rect.height());
progressIndicator->move(rect.x(), rect.y());
setStyleSheet(QString("padding-left: %1px;").arg(progressIndicator->width()));
}@Before first resize:
!http://storage5.static.itmages.ru/i/12/0319/h_1332143675_5309478_7d93cf004c.png(before)!
After:
!http://storage9.static.itmages.ru/i/12/0319/h_1332143617_2963291_2d021625b1.png(after)!