Results 1 to 4 of 4

Thread: Custom QLineEdit....highlighting

  1. #1
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Custom QLineEdit....highlighting

    I have a class that inherits QLineEdit. It overrides the paintEvent method to draw a custom look. For the original QLineEdit, you can highlight text with a mouse button drag, and I assume on most systems it's a blue highlight with white text. My custom QLineEdit widget can paint the text and it can select text using the mouse, but no highlight ever shows up. It is like it is invisible. Any suggestions on how to get the highlighting to work? If I have to do it manually inside paintEvent where do I start?

  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: Custom QLineEdit....highlighting

    Yes, it would be done by the paint event of QLineEdit using the style options. The place to start would be the Qt source.

  3. #3
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom QLineEdit....highlighting

    Just wondering, since I'm inheriting from QLineEdit, shouldn't there be some sort of default highlighting that happens even if I override paintEvent? What's happening right now is that it's invisibly highlighting with no default highlight of blue/white. The following code has no effect:

    Qt Code:
    1. QPalette p = this->palette();
    2. p.setColor( QPalette::Highlight, Qt::blue );
    3. p.setColor( QPalette::HighlightedText, Qt::white );
    4. this->setPalette( p );
    To copy to clipboard, switch view to plain text mode 
    Last edited by Plissken; 3rd July 2012 at 06:06.

  4. #4
    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: Custom QLineEdit....highlighting

    You are replacing the paintEvent from the inherited class. If your paintEvent doesn't paint the selected text in some alternate way, or delegate to something that does, then it won't be painted.

    Are you sure that the desired overall effect cannot be more simply achieved with style sheets?

Similar Threads

  1. QLineEdit with Completer custom delegate
    By zishanj in forum Qt Programming
    Replies: 0
    Last Post: 23rd April 2011, 17:32
  2. Custom QLineEdit to store NULL with QDataWidgetMapper
    By certqt in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2010, 13:15
  3. Replies: 1
    Last Post: 12th October 2010, 22:20
  4. Custom widget with frame like QLineEdit
    By cil in forum Qt Programming
    Replies: 13
    Last Post: 15th April 2010, 11:58
  5. Replies: 5
    Last Post: 1st April 2009, 12:16

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.