Results 1 to 8 of 8

Thread: How to embed label in lineedit?

  1. #1
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt/Embedded
    Platforms
    Windows

    Question How to embed label in lineedit?

    How to embed label in lineedit?
    or overlapping label above lineedit, so to look like the label is inside lineedit box?
    see attached sceenshot
    Attached Images Attached Images
    Last edited by blonde; 1st December 2009 at 07:37. Reason: Add screenshot

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to embed label in lineedit?

    Quote Originally Posted by blonde View Post
    How to embed label in lineedit?
    or overlapping label above lineedit, so to look like the label is inside lineedit box?
    Create the label with line edit as parent and set the layout properly.

  3. #3
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to embed label in lineedit?

    Put the text in the lineedit with setText(). Subclass the lineedit and capture keypresses so you can filter out the keypresses (cursor left, home, backspace) that would move the cursor into the forbidden area.

  4. #4
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt/Embedded
    Platforms
    Windows

    Default Re: How to embed label in lineedit?

    with yogeshgokul's solution, the LineEdit's cursor starts from the beginning,
    the user inputs covers the label, label acts as a background.
    How can you make the curor starts after the label?

  5. #5
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to embed label in lineedit?

    Quote Originally Posted by blonde View Post
    with yogeshgokul's solution, the LineEdit's cursor starts from the beginning,the user inputs covers the label, label acts as a background.
    How can you make the curor starts after the label?
    Why dont you create your own widget? And design it how ever you want. Because in Qt any widget can be parent of any widget. So enjoy this freedom

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to embed label in lineedit?

    Quote Originally Posted by yogeshgokul View Post
    Why dont you create your own widget?
    Because painting a QLineEdit with the blinking cursor is not as trivial as it seems for beginners... But after setting the label above the line edit just use QWidget::setContentsMargins() on the line edit (with the size of the label) and the label will stop to overlay the input text.

  7. #7
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt/Embedded
    Platforms
    Windows

    Default Re: How to embed label in lineedit?

    Quote Originally Posted by Lykurg View Post
    Because painting a QLineEdit with the blinking cursor is not as trivial as it seems for beginners... But after setting the label above the line edit just use QWidget::setContentsMargins() on the line edit (with the size of the label) and the label will stop to overlay the input text.
    lineedit setContentsMargins() indents the lineedit box, it made the label out of the lineedit box.

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to embed label in lineedit?

    Ups, I've ment: QLineEdit::setTextMargins().

Similar Threads

  1. QCheckBox with long text label
    By Ferdous in forum Newbie
    Replies: 5
    Last Post: 29th October 2011, 19:05
  2. How to update lineEdit
    By HelloDan in forum Qt Programming
    Replies: 9
    Last Post: 17th February 2009, 07:01
  3. tool buttons on top of label
    By McKee in forum Qt Programming
    Replies: 5
    Last Post: 2nd November 2008, 16:07
  4. Copy / Paste doesn't work with LineEdit
    By ia32 in forum Qt Tools
    Replies: 2
    Last Post: 5th May 2008, 21:44
  5. Replies: 1
    Last Post: 24th October 2006, 16:40

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.