I need to implement LineEdit
widget with possibility to add tool buttons at the right end of text area. I know two ways of doing that but both solutions seems ugly.
1) add tool buttons as child widgets of QLineEdit
and handle resizeEvent
to position them correctly. The main disadvantage is that if text is enough long it may appear under tool buttons.
2) Another solution is to put line edit and buttons inside frame and overwrite style to hide lineEdits
frame and make QFrame
look like QLineEdit
.
I need a best way to implement such widget. Also my widget should be style aware.
The original blog post is gone now, but Trolltech once posted an example of a clear button for Qt 4.
Results
Line edit with no text:
Line edit with some text (button appears):
Line edit full of text (doesn’t go underneath button):
Source
lineedit.h
lineedit.cpp