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. Disabled QLineEdit Background Color
Forum Updated to NodeBB v4.3 + New Features

Disabled QLineEdit Background Color

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 9.0k 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.
  • T Offline
    T Offline
    tecknophreak
    wrote on last edited by
    #1

    Ok, I've searched around and keep finding the same solution:

    @MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    QLineEdit *edit;
    edit = new QLineEdit();
    edit->setText("Lineedit");

    edit->setDisabled(true);
    QPalette pal = edit->palette();
    pal.setColor(QPalette::Disabled, QPalette::Text, pal.color(QPalette::Active, QPalette::Text));
    pal.setColor(QPalette::Disabled, QPalette::Base, pal.color(QPalette::Active, QPalette::Base));
    edit->setPalette(pal);
    setCentralWidget(edit);
    

    }@

    Actually, the above is what I got from the FAQs, but I've seen the solution in a few other threads here and there. However, my background color remains the same, grey. I've put in an RGB of 0xff, 0, 0 with the same results. If I take out the edit->setDisabled(true), I have an editable field with a red background. I'm using QT Creator 1.3.1 based on QT 4.6.2.

    Any Ideas? Thanks!

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      Yash
      wrote on last edited by
      #2

      Try using QSS . Search for css in docs. Let me know if you fail to achieve.

      http://kineticwing.com : Web IDE, QSS Editor
      http://speedovation.com : Development Lab

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tecknophreak
        wrote on last edited by
        #3

        Well, I didn't want to use the QSS, just so that I could keep it all in source(at least for now). It turns out I didn't do a few steps, for one, call setAutoFillBackground(true). That then filled in the background(not of the text, but of the line edit) red. So I changed p.setColor(QPalette::Base, Qt::white) to p.setColor(QPalette::Background, Qt::white) and it worked.

        I guess I misread the QPalette enum documentation. So it's solved.

        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