Results 1 to 5 of 5

Thread: problem with QLineEdit and QPalette

  1. #1
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default problem with QLineEdit and QPalette

    I have defined a QLineEdit in the "BaseForm" constructor as
    Qt Code:
    1. boxLayout = new QVBoxLayout ( frameD );
    2. inputStripLayout = new QHBoxLayout ( );
    3. boxLayout->addLayout ( inputStripLayout );
    4.  
    5. lbCategory = new QLabel("Category #");
    6. lbCategory->setFont ( fb );
    7. inputStripLayout->addWidget ( lbCategory );
    8.  
    9. leCategoryNumber= new QLineEdit();
    10. leCategoryNumber->setAlignment ( Qt::AlignCenter );
    11. leCategoryNumber->setPalette ( palE );
    12. leCategoryNumber->setFont ( fb );
    13. leCategoryNumber->setMaximumWidth(30);
    14. leCategoryNumber->setEnabled(false);
    15.  
    16. inputStripLayout->addWidget ( leCategoryNumber)
    To copy to clipboard, switch view to plain text mode 
    and I want to change the color of the QLineEdit and set the focus with
    Qt Code:
    1. void BaseForm::slotPb1()
    2. {
    3. catNum->inputCatNum();
    4. Pb1->setText("-");
    5. Pb2->setText("Cat'ory");
    6. leCategoryNumber->setPalette ( QColor (17, 255, 255) );
    7. leCategoryNumber->setEnabled(true);
    8. leCategoryNumber->setFocus();
    To copy to clipboard, switch view to plain text mode 
    I get the "focus" ok, but I get a "white" box, not the "blue" one I want. Looked at the QPalette" documentation and don't understand a word of it. I am sure there is a simple way to togle colors on a QLineEdit" as a signal for "User" input. But I couldn't find it .
    Thanks in advance for you help.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with QLineEdit and QPalette

    You can try sylesheets: http://doc.trolltech.com/4.4/stylesh...zing-qlineedit . It's easier.

  3. The following user says thank you to marcel for this useful post:

    impeteperry (15th October 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: problem with QLineEdit and QPalette

    Amazing!! "Enhancements to the point of non-usability"

    But
    Qt Code:
    1. The background of a read only QLineEdit can be modified as below:
    2.  
    3. QLineEdit:read-only {
    4. background: lightblue;
    To copy to clipboard, switch view to plain text mode 
    I want to change the color when it has the focus.!!!
    Last edited by impeteperry; 15th October 2008 at 16:35.

  5. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with QLineEdit and QPalette

    I think you will need to re-implement the focusInEvent and focusOutEvent of QWidget. In these methods you will have to write code to change the palette of the QLineEdit.

  6. #5
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with QLineEdit and QPalette

    The stylesheet documentation http://doc.trolltech.com/4.4/stylesheet-reference.html shows you can use the "focus" state like so

    Qt Code:
    1. QLineEdit:focus {
    2. background: lightblue;
    3. }
    To copy to clipboard, switch view to plain text mode 

    Haven't tried it (I'm still at work) but it should work

    Pete

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.