Pixel Length of a QString
-
I need to resize QLineEdits depending on the QString inside.
On StackOverFlow i found this:
@
QLineEdit lineEdit;
QFontMetrics fm(lineEdit->fontMetrics());
int pixelLength = fm.width(lineEdit->text());
lineEdit->setFixedWith(pixelLength);
@But the QLineEdit will be a bit too small to show the full string.
So what is the correct way to resize a QLineEdit depending on the given QString?
(Working with C++ 11, Qt 5.1.1, Win7)
-
Perhaps resizing the viewport of a QLineEdit would help?
Or else the size of the viewport compared with the size of the QLineEdit would give you the data needed tot calculate the new size of the QLineEdit. Don't forget about the margins and padding ofcourse.
-
See "here":http://qt-project.org/forums/viewthread/3427
Don't know if QLineEdit has one though, but in case not there is probably some other possibility to get the inner rectangle.
-
Just checked, no viewport in QLineEdit, sorry.
Perhaps you can use the paintRect in the QPainEvent?