Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How can I set background of TextField to white
Qt 6.11 is out! See what's new in the release blog

How can I set background of TextField to white

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 2.9k Views
  • 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
    maxwell31
    wrote on last edited by
    #1

    Well, the title is my question: How can I set background of TextField to white. I am using the Material Style btw.

    J.HilkJ 1 Reply Last reply
    0
    • M maxwell31

      Well, the title is my question: How can I set background of TextField to white. I am using the Material Style btw.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @maxwell31

      TextField has background property you can assign it a Rectangle and set that color to white
      e.g:

      TextField{
           background: Rectangle{color:white}
      }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

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

        Thanks. That was what I first tried. However, I was unhappy with it, as it would remove the coloured line, present in Material style. It turns out, that this coloured line is actually the background (from QtQuick/Controls.2/Material/TextField.qml):

           background: Rectangle {
               y: control.height - height - control.bottomPadding + 8
               implicitWidth: 120
               height: control.activeFocus || control.hovered ? 2 : 1
               color: control.activeFocus ? control.Material.accentColor
                                          : (control.hovered ? control.Material.primaryTextColor : control.Material.hintTextColor)
           }
        

        So if I want to keep that line, I guess I need to put my TextField into a parent Rectangle for the background, right?

        J.HilkJ 1 Reply Last reply
        0
        • M maxwell31

          Thanks. That was what I first tried. However, I was unhappy with it, as it would remove the coloured line, present in Material style. It turns out, that this coloured line is actually the background (from QtQuick/Controls.2/Material/TextField.qml):

             background: Rectangle {
                 y: control.height - height - control.bottomPadding + 8
                 implicitWidth: 120
                 height: control.activeFocus || control.hovered ? 2 : 1
                 color: control.activeFocus ? control.Material.accentColor
                                            : (control.hovered ? control.Material.primaryTextColor : control.Material.hintTextColor)
             }
          

          So if I want to keep that line, I guess I need to put my TextField into a parent Rectangle for the background, right?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @maxwell31
          I have no idea how that TextField looks in that material style x)

          but maybe something like this will work ?

          background: Rectangle{
              color: "white"
              Rectangle {
                 y: control.height - height - control.bottomPadding + 8
                 implicitWidth: 120
                 height: control.activeFocus || control.hovered ? 2 : 1
                 color: control.activeFocus ? control.Material.accentColor
                                            : (control.hovered ? control.Material.primaryTextColor : control.Material.hintTextColor)
             }
          }
          

          quick and dirty 😉


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1

          • Login

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