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. Make Line Edit Uneditable and Change the background color
Forum Updated to NodeBB v4.3 + New Features

Make Line Edit Uneditable and Change the background color

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 21.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.
  • D Offline
    D Offline
    DouDou
    wrote on last edited by
    #1

    Hi,

    I cant figure out how to make a Line Edit uneditable. Basically I dont want the user to be able to change the content by clicking on the widget edit it with his keyboard, because I have a set of buttons that allow specific changes.

    My second question is how to change the background color from the default white, i didnt see the option under widget properties. Thanks

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

      You can disable QLineEdit using method "setEnabled ( false )":http://qt-project.org/doc/qt-4.8/qwidget.html#enabled-prop which is inherited from QWidget.

      You can change the background color using "QPalette":http://qt-project.org/doc/qt-4.8/qpalette.html. The source code should be something like:
      @
      QPalette palette = lineEdit.palette();
      palette.setColor(QPalette::Base, QColor(255,0,0)); //Red
      lineEdit.setPalette(palette);
      @

      http://anavi.org/

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

        Is there some reason, then, to have the text in a QLineEdit? Perhaps a QLabel would be your better option. It's always better to use a widget for its intended use, rather than try to shoehorn in different functionality that the user might not expect.

        With that said, you're probably looking for @lineEdit->setReadOnly(true);@

        And for your second issue, you can use "stylesheets":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qabstractscrollarea to change background-color.

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

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

          [quote author="mlong" date="1331135892"]Is there some reason, then, to have the text in a QLineEdit? Perhaps a QLabel would be your better option. [/quote]

          I guess that the goal is to enable/disable the QLineEdit instance depending the status of the application.

          http://anavi.org/

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

            I would think so, but wasn't sure because of the context of

            bq. I have a set of buttons that allow specific changes.

            If that means that a particular button enables/disables a QLineEdit, then it makes sense. But if it means that you click a button to make the text something predefined (which just needs to be displayed) then it may not be the best solution.

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

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

              [quote author="mlong" date="1331136920"]If that means that a particular button enables/disables a QLineEdit, then it makes sense. But if it means that you click a button to make the text something predefined (which just needs to be displayed) then it may not be the best solution.
              [/quote]

              Yes, absolutely. I totally agree that in the second case it would be better to use QLabel.

              http://anavi.org/

              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