Windows 7 SP1
MSVS 2010
Qt 4.8.4
This code:
#include <QTGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow* window = new QMainWindow;
QLineEdit* line_edit = new QLineEdit;
line_edit->setText("ABCDEFG");
line_edit->setFixedSize(40,20);
window->setCentralWidget(line_edit);
window->show();
return app.exec();
}
Displays this:
Note that the "AB" is truncated and the cursor is at the end of the line edit.
I want it to display:
Here "FG" is truncated and the cursor is at the beginning of the line edit.
I've tried to setCursorPosition and cursorBackward to no avail. If I convert the text via the font metric's elidedText it will display from the beginning with the trailing "...". But I don't want to do that.
Question: Is there a way to make the cursor to start at the beginning of its contents after displaying a QLineEdit?
Insert cursor at the beginning of every selected line: As soon as you see the cursor blinking at the end of every line, do the following: Windows: tab twice on your keyboard’s home button. Now you can add whatever you need to at the beginning of your lines.
Vim has a straightforward way to move the cursor to the end of the line. Again, you need to be in Normal mode to do this. It does not matter in which column your cursor, only which line it is on. Then, press the $ key and it will move the cursor to the end of the line.
As soon as you see the cursor blinking at the end of every line, do the following: Windows: tab twice on your keyboard’s home button. Now you can add whatever you need to at the beginning of your lines.
Setting cursor position to 0 just after setting text should work just fine. At least it does here on Linux, Qt 4.8.3.
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow* window = new QMainWindow;
QVBoxLayout* layout = new QVBoxLayout;
QLineEdit* line_edit = new QLineEdit;
line_edit->setText("ABCDEFG");
line_edit->setFixedSize(40,20);
line_edit->setCursorPosition(0);
layout->addWidget(line_edit);
window->setCentralWidget(line_edit);
window->show();
return app.exec();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With