Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-95928

QLineEdit: leading action icon and text overlap

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Duplicate
    • Affects Version/s: 6.1.2
    • Fix Version/s: None
    • Labels:
      None
    • Platform/s:
      All

      Description

      When doing a simple:

      QLineEdit le;
      le.addAction(someIcon, QLineEdit::LeadingPosition);
      le.setClearButtonEnabled(true);
      le.setPlaceholderText(u"Search");
      

      Then, the icon and placeholder text overlap like this:

      (non-empty text also overlaps with the icon in this case)

       

      I've been debugging this issue using the regular Qt 6.1.2 release in Visual Studio / Windows, and I found out it seems to come from:

       

      QLineEditToolButton::needsSpace() returns m_wasHidden, which in the case of a regular leading action icon's widget, is never set to true, because the widget is not updated at the right moment, and does not have the right flags set.

       

      m_wasHidden is set to true only with animateShow(true), which is never called in this case because:

      1. displayWidgets() is called in response to text change/edit: this is the first unexpected thing, we would expect the action icon's widget to be displayed and visible even with empty/placeholder text by default, and not just for non-empty text (there is a flag for that, which is not accessible when using the QLineEdit::addAction() API, so by default, we might expect the icon visibility to be independent from the text being empty)
      2. logically, the flag SideWidgetFadeInWithText is not set for the action, which is a second reason why the animateShow() is never called here. Seems logical indeed, but it creates the issue where we're not interrogating the right thing when checking for widget visibility

      What seems wrong to me is the test that's done in effectiveTextMargin() when animation is enabled (which is in a regular Qt install). maybe a more elaborate condition is needed here, or a different logic, but clearly something's missing when calculating QLineEditPrivate::effectiveTextMargins().

       

      Perhaps QLineEditIconButton::needsSpace() should be implemented like this:

      bool needsSpace() const { return isVisible() || m_wasHidden; }

      ?

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              vhilshei Volker Hilsheimer
              Reporter:
              moretromain Romain Moret
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes