Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add an Error image in QLineEdit when the Input Text is Invalid ?

How to add an Error image in QLineEdit when the Input Text is Invalid ?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 8.3k 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.
  • M Offline
    M Offline
    Macro
    wrote on last edited by
    #1

    Hi...

    I have a QLineEdit in that I have setted the Maximum value as 1000. Suppose if I Enter 125436 as input text then i have to add an error image at the right corner of the QLineEdit indicating that the entered text is InValid.. I tried using Stylesheets,

    @background-image: url(:/folder/image.png)@

    but it doesn't work.. please post your suggestions...

    Thanks & Regards...

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      Check the solutions provided at similar threads:

      • "The background-color of the QLineEdit":http://qt-project.org/forums/viewthread/2640
      • "Background-image for QLineEdit":http://stackoverflow.com/questions/7324857/background-image-for-qlineedit

      http://anavi.org/

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Macro
        wrote on last edited by
        #3

        Thanks for your sggestion leon.anavi...

        Already I checked that similar threads and tried.. Eventhough it is not working.. :(

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If your input are only numbers, why not use a QSpinBox ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Macro
            wrote on last edited by
            #5

            Yeah i can make use of a Spin Box... but that is not my Requirement... My requirement is to add an image in the QLineEdit when the input is invalid...

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on last edited by
              #6

              [quote author="Rochi" date="1363090439"]Thanks for your sggestion leon.anavi...

              Already I checked that similar threads and tried.. Eventhough it is not working.. :([/quote]

              According to the thread fro stackoverflow.com it will not work without:

              @border: 1px solid #000000;@

              Have you tried to append it to the style?

              [quote author="SGaist" date="1363090779"]If your input are only numbers, why not use a QSpinBox ?[/quote]

              Honestly if I was implementing this solution instead of setting the background I would just place an label with an image on the right side of the input box and display it only when it is needed :)

              http://anavi.org/

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

                You could adapt the "example":http://blog.qt.digia.com/blog/2007/06/06/lineedit-with-a-clear-button/ floating about on the net on how to add a clear button to a line edit. Only, you don't need a button, but a label with a small image on it.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Macro
                  wrote on last edited by
                  #8

                  Here's my qss code...

                  @QLineEdit[OutOfRange= "true"]
                  {
                  border-style: solid; border: 2px solid red; color: red; border-radius: 8px; background-image: url(:/resources/Error.png); background-color: yellow; background-repeat: no-repeat; background-position: right;
                  }@

                  Also i tried using the background-position.. But No use....

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    I've checked your code and it shows the image in my test. The only thing I can think of is maybe your resource image can't be found for any reason? Have you checked it anywhere else?

                    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 Extensions
                    • Unsolved