Results 1 to 5 of 5

Thread: Get Color from LineEdit

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Get Color from LineEdit

    Hello everybody,

    OS:Winxp
    QT 4.1.3

    I can set a color to a lineedit, now i would like to get the color. is this possible?

    set color:
    ui.l1_le->setPaletteBackgroundColor("yellow");

    get color:
    ?????

    Thanks
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Get Color from LineEdit

    paletteBackgroundColor()

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

    raphaelf (16th May 2007)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Get Color from LineEdit

    Quote Originally Posted by raphaelf View Post
    ui.l1_le->setPaletteBackgroundColor("yellow");
    QWidget::setPaletteBackgroundColor() is a Qt3 support member.

    Qt Code:
    1. // set
    2. QPalette palette = ui.l1_le->palette();
    3. palette.setColor(ui.l1_le->backgroundRole(), Qt::yellow);
    4. ui.l1_le->setPalette(palette);
    5.  
    6. // get
    7. QColor color = ui.l1_le->palette().color(ui.l1_le->backgroundRole());
    To copy to clipboard, switch view to plain text mode 

    Instead of "ui.l1_le->backgroundRole()" you may also directly use QPalette::Base which is used as a background role of text entry widgets.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    raphaelf (16th May 2007)

  6. #4
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Get Color from LineEdit

    Hello,

    Thank you very much..

    But how could i convert it to String?
    For this for example:
    QColor color = ui.l1_le->palette().color(ui.l1_le->backgroundRole());
    QMessageBox::information(this,"LernIT",color);
    Think DigitalGasoline

  7. #5
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Get Color from LineEdit

    I could solve my problem like that:

    Thanks

    Qt Code:
    1. QColor color = ui.l1_le->palette().color(ui.l1_le->backgroundRole());
    2. //QMessageBox::information(this,"LernIT",QString::number(a));
    3.  
    4.  
    5.  
    6. if (color == "#ffff00")
    7. insert();
    8.  
    9.  
    10. else
    11. solve();
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

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
  •  
Qt is a trademark of The Qt Company.