static string x; x=ui->lineEdit->text().toStdString();if(x==?????)
ui->lineEdit->displayText().isEmpty()
C++ (Qt)#ifndef LINEED_H#define LINEED_H #include <QtWidgets> class LineEd : public QLineEdit { protected: virtual void mousePressEvent(QMouseEvent*) { clear(); } public: LineEd(QWidget *wgt = 0) : QLineEdit(wgt) {} }; #endif // LINEED_H
C++ (Qt)#include <QtWidgets>#include "lineed.h" int main(int argc, char** argv) { QApplication app(argc, argv); QWidget wgt; LineEd *LnEd = new LineEd; QVBoxLayout* vLayout = new QVBoxLayout; vLayout->addWidget(LnEd); wgt.setLayout(vLayout); wgt.show(); return app.exec(); }
C++ (Qt)#include <QtWidgets>#include "lineed.h" int main(int argc, char** argv) { QApplication app(argc, argv); LineEd LnEd; LnEd.show(); return app.exec();}
C++ (Qt)#ifndef LINEED_H#define LINEED_H #include <QtWidgets> class LineEd : public QLineEdit { protected: virtual void mousePressEvent(QMouseEvent*) { if(text() == "My Text") clear(); } public: LineEd(QWidget *wgt = 0) : QLineEdit(wgt) {} }; #endif // LINEED_H