Hmm, I didn't quite understand your answer. I must be missing something. Here's a complete example. I would like the text to be highlighted as soon as I click in the textbox.
#ifndef MYLINEEDIT_H
#define MYLINEEDIT_H
#include <QtGui>
{
Q_OBJECT
protected:
};
#endif // MYLINEEDIT_H
#ifndef MYLINEEDIT_H
#define MYLINEEDIT_H
#include <QtGui>
class MyLineEdit : public QLineEdit
{
Q_OBJECT
protected:
void focusInEvent(QFocusEvent *);
};
#endif // MYLINEEDIT_H
To copy to clipboard, switch view to plain text mode
#include "mylineedit.h"
//this->clear();
this->selectAll();
}
#include "mylineedit.h"
void MyLineEdit::focusInEvent(QFocusEvent *) {
//this->clear();
this->selectAll();
}
To copy to clipboard, switch view to plain text mode
#include "mylineedit.h"
#include <QtGui>
int main(int argc, char *argv[])
{
MyLineEdit *tmp = new MyLineEdit();
tmp->setText("test this");
flayout->addWidget(tmp);
f->setFocus();
f->show();
return app.exec();
}
#include "mylineedit.h"
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFrame *f = new QFrame();
MyLineEdit *tmp = new MyLineEdit();
tmp->setText("test this");
QHBoxLayout *flayout = new QHBoxLayout(f);
flayout->addWidget(tmp);
f->setFocus();
f->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks