Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to insert QProgressIndicator into QLineEdit?
Qt 6.12 LTS is out! See what's new in the release blog

How to insert QProgressIndicator into QLineEdit?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RazrFalcon
    wrote on last edited by
    #1

    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)!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RazrFalcon
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Could you show the code you now have, please?
          You should of course still position the indicator manually inside the resizeEvent implementation.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RazrFalcon
            wrote on last edited by
            #5

            @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)!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt
            • Unsolved