add QLabel into QLineEdit
- 
i also think the input mask is actually the best way, or maybe even better a custom QValidator. 
 But to just add something to the (rather ugly) QLabel idea: You could use QLineEdit::setTextMargins() to move the left-most position of the cursor.@raven-worx yes I agree the input mask Is the best way to go. However, it's a new concept for me since I never heard of it. That is why I am very confused to how it works. 
- 
@raven-worx yes I agree the input mask Is the best way to go. However, it's a new concept for me since I never heard of it. That is why I am very confused to how it works. @raven-worx said: 
 setTextMargins
 +1 That would work for custom control.yes, you would need to put \ into your date. 
 the AAAA is input specifier .
 Go to a LineEdit and find inputmask property and press F1 to read about them.
- 
@raven-worx said: 
 setTextMargins
 +1 That would work for custom control.yes, you would need to put \ into your date. 
 the AAAA is input specifier .
 Go to a LineEdit and find inputmask property and press F1 to read about them.@mrjj So if the user is allowed 100 characters for the QLineEdit do I have to put 100 A's? 
- 
@mrjj So if the user is allowed 100 characters for the QLineEdit do I have to put 100 A's? @marlenet15 erhm, yes I think. maybe there is way 
 but inputmasks are normally used for short input like date
 or iP etc
- 
@mrjj So if the user is allowed 100 characters for the QLineEdit do I have to put 100 A's? @marlenet15 
 if you are familiar with regular expressions you might want to use QRegExpValidator which will result in the same behavior
 And set it on the line edit.
- 
@marlenet15 
 if you are familiar with regular expressions you might want to use QRegExpValidator which will result in the same behavior
 And set it on the line edit.@raven-worx 
 oh. So QRegExpValidator can have static text?
- 
@raven-worx 
 oh. So QRegExpValidator can have static text?@mrjj 
 Of course, a regular expression can have a static text included
- 
@mrjj 
 Of course, a regular expression can have a static text included@raven-worx 
 yes, but i didn't know it would show in lineEdit as Validator sounds so none visual :)
- 
@mrjj 
 Of course, a regular expression can have a static text included@raven-worx Can you please show me an example of that? I have never heard of that and I googled it and I didn't find anything about that :) 
- 
@raven-worx Can you please show me an example of that? I have never heard of that and I googled it and I didn't find anything about that :) @marlenet15 
 you can see how to use QRegExpValidator in the link i've posted.
 Use a RegExp similiar to this one. There are tons of material on the web about regexp to learn.QRegExp("Comments\\: ([Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec] [0-3]?[0-9] [0-9]{4}\\: (.+))");This regexp is surely not perfect, but enough to get an idea and continue to learn the syntax i guess. 
- 
@marlenet15 
 you can see how to use QRegExpValidator in the link i've posted.
 Use a RegExp similiar to this one. There are tons of material on the web about regexp to learn.QRegExp("Comments\\: ([Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec] [0-3]?[0-9] [0-9]{4}\\: (.+))");This regexp is surely not perfect, but enough to get an idea and continue to learn the syntax i guess. @raven-worx 
 If I may interject,[Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec]is not okay for matching one should use a (non-capturing) group instead. i.e:(?:Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec).
- 
My two cents: if you have Qt5, consider using QRegularExpressionValidator and QRegularExpression instead, since the motor has been remarkably improved. 
- 
@marlenet15 
 you can see how to use QRegExpValidator in the link i've posted.
 Use a RegExp similiar to this one. There are tons of material on the web about regexp to learn.QRegExp("Comments\\: ([Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec] [0-3]?[0-9] [0-9]{4}\\: (.+))");This regexp is surely not perfect, but enough to get an idea and continue to learn the syntax i guess. @raven-worx I just tried it and the amazing thing is the cursor moves automatically moves to the right of the date. However, I can still edit the date and I don't want it to be edited whatsoever. When the mouse clicks the QLineEdit, I want it so that the cursor starts right after the date text. :( Is it possible for this? Thank you so much for you help! This is the code I used: QRegExp rx("Comments\\: ([Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec] [0-3]?[0-9] [0-9]{4}\\: (.+))"); QValidator *validator = new QRegExpValidator(rx, this); ui->lineEdit->setValidator(validator); QDate date = QDate::currentDate(); QTime time = QTime::currentTime(); ui->lineEdit->setText(date.toString("MMM dd yyyy")+" "+time.toString("hh:mm:ss"));
- 
@raven-worx I just tried it and the amazing thing is the cursor moves automatically moves to the right of the date. However, I can still edit the date and I don't want it to be edited whatsoever. When the mouse clicks the QLineEdit, I want it so that the cursor starts right after the date text. :( Is it possible for this? Thank you so much for you help! This is the code I used: QRegExp rx("Comments\\: ([Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec] [0-3]?[0-9] [0-9]{4}\\: (.+))"); QValidator *validator = new QRegExpValidator(rx, this); ui->lineEdit->setValidator(validator); QDate date = QDate::currentDate(); QTime time = QTime::currentTime(); ui->lineEdit->setText(date.toString("MMM dd yyyy")+" "+time.toString("hh:mm:ss"));Try this: QString dateTimeStr = QDateTime::currentDateTime().toString("MMM dd yyyy hh:mm:ss"); QString rxStr("Comments\\: %1\\: (.+)"); QRegExp rx( rxStr.arg(dateTimeStr), Qt::CaseSensitive, QRegExp::RegExp2 ); QValidator *validator = new QRegExpValidator(rx, this); ui->lineEdit->setValidator(validator);
- 
Try this: QString dateTimeStr = QDateTime::currentDateTime().toString("MMM dd yyyy hh:mm:ss"); QString rxStr("Comments\\: %1\\: (.+)"); QRegExp rx( rxStr.arg(dateTimeStr), Qt::CaseSensitive, QRegExp::RegExp2 ); QValidator *validator = new QRegExpValidator(rx, this); ui->lineEdit->setValidator(validator);@raven-worx I can still edit the date_time stamp :( 
- 
@raven-worx I can still edit the date_time stamp :( @marlenet15 
 Hello,
 I believe you are going to need an input mask after all. I think you should try something like this:QString date = QDateTime::currentDateTime().toString("MMM dd yyyy hh:mm:ss"); QString heading = QStringLiteral("Comments %1: %2").arg(date); //< Construct the heading QRegularExpression escaperx(QStringLiteral("([AaNnXx09Dd#HhBb><!\\\\]{1})")); //< Escape regex for input mask special characters heading.replace(escaperx, QStringLiteral("\\\\1")); //< Escape the input mask QString mask = heading.arg("", 255, QLatin1Char('x')); //< Add 255 optional characters to the mask for the user to fill. _dateLabel->setInputMask(mask);Then if you wish you could add a validator to ensure the user has entered correct data. Kind regards. EDIT: 
 I had forgotten to add the actual characters that the user can fill to the mask, but I edited the example and it should be correct now.
- 
@marlenet15 
 Hello,
 I believe you are going to need an input mask after all. I think you should try something like this:QString date = QDateTime::currentDateTime().toString("MMM dd yyyy hh:mm:ss"); QString heading = QStringLiteral("Comments %1: %2").arg(date); //< Construct the heading QRegularExpression escaperx(QStringLiteral("([AaNnXx09Dd#HhBb><!\\\\]{1})")); //< Escape regex for input mask special characters heading.replace(escaperx, QStringLiteral("\\\\1")); //< Escape the input mask QString mask = heading.arg("", 255, QLatin1Char('x')); //< Add 255 optional characters to the mask for the user to fill. _dateLabel->setInputMask(mask);Then if you wish you could add a validator to ensure the user has entered correct data. Kind regards. EDIT: 
 I had forgotten to add the actual characters that the user can fill to the mask, but I edited the example and it should be correct now.@kshegunov it works thank you very much and to everyone! 
- 
@kshegunov it works thank you very much and to everyone! @marlenet15 
 No problem, I'm glad I could be of assistance.
