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 change QLineEdit border color only?

How to change QLineEdit border color only?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 4.0k Views 3 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.
  • Barry ScottB Offline
    Barry ScottB Offline
    Barry Scott
    wrote on last edited by
    #1

    My goal is to change the border color of QLineEdit based on the value of a property "valid".

    I have added this style:

    QLineEdit[valid=false] {border: 1px solid red}

    And when I set the property "valid" to false and do the unpolish(), polish() dance I see the red border.

    But the border radius is changed as is the padding.

    How do I only change the border color and leave the padding and border radius at the default value?

    I have considered finding the values of the border radius and padding, but did not find an API call that will return this information.

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

      Hi,

      Currently you can't. Setting a style sheet will modify which Style is used to render a widget. You'll have to modify you style sheet to also alter the border radius.

      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
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        I was thinking that maybe you could just reimplement paintEvent() and override the pen used to draw the frame.

        Have a look at the source of QLineEdit, it shouldn't be impossible

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        0
        • Barry ScottB Offline
          Barry ScottB Offline
          Barry Scott
          wrote on last edited by
          #4

          And I take it that I cannot get the default radius in any way?

          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