Results 1 to 3 of 3

Thread: QColorDialog problem

  1. #1
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QColorDialog problem

    Hi all

    I have one button and textEdit and when user press that button, ColorDialog should appear and using stylesheet selected color should apply to all text in textEdit. I made the following code:


    QColor color = QColorDialog::getColor(Qt::black, this);

    edit->setStyleSheet(color.name()); (edit is QTextEdit)

    but it's not working, ColorDialog appears, and I select color, but text in textEdit remains as it is. Can someone help me with this.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QColorDialog problem

    The QString returned by QColor::name() is not a valid style sheet. You want something like:
    Qt Code:
    1. edit->setStyleSheet(QString("QTextEdit { color: %1; }").arg(color.name()));
    To copy to clipboard, switch view to plain text mode 
    or you can use the QColor directly on the widget's palette.
    Qt Code:
    1. QPalette pal = edit->palette();
    2. pal.setBrush(QPalette::Text, color);
    3. edit->setPalette(pal);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2012
    Posts
    55
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QColorDialog problem

    thank you, it's working now

Similar Threads

  1. QColorDialog
    By angarali06 in forum Newbie
    Replies: 1
    Last Post: 17th April 2011, 19:02
  2. QColorDialog
    By BrainFreeze in forum Qt Programming
    Replies: 3
    Last Post: 6th March 2011, 04:45
  3. Using <QColorDialog>
    By Gily in forum Newbie
    Replies: 5
    Last Post: 26th December 2007, 20:26
  4. Please help ASAP::QColorDialog
    By LiCodeX in forum Newbie
    Replies: 2
    Last Post: 2nd October 2007, 12:16
  5. QColorDialog Apperance?
    By antonio.r.tome in forum Qt Programming
    Replies: 9
    Last Post: 16th April 2006, 07:43

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.