-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathresolutionlineedit.cpp
More file actions
28 lines (24 loc) · 934 Bytes
/
resolutionlineedit.cpp
File metadata and controls
28 lines (24 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "resolutionlineedit.h"
#include <QRegularExpression>
#include <QRegularExpressionValidator>
ResolutionLineEdit::ResolutionLineEdit(QWidget *parent) : QLineEdit(parent) {
// Regular expression to match the format WxH, where W and H are integers
QRegularExpression regExp("^\\d+x\\d+$");
QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);
setValidator(validator);
}
void ResolutionLineEdit::focusOutEvent(QFocusEvent *event) {
QString text = this->text();
if (text.contains('x')) {
QStringList parts = text.split('x');
if (parts.size() == 2) {
int width = parts.at(0).toInt();
int height = parts.at(1).toInt();
if (width < 64 || height < 64) {
// If either value is less than 64, clear the input
setText("");
}
}
}
QLineEdit::focusOutEvent(event);
}