검색결과 리스트
QTextEdit에 해당되는 글 1건
- 2018.03.12 QTextEdit maxlength implement
QTextEdit에는 setMaxLength 함수가 없다
입력 글자수를 제한하기 위해서 다음과 같이 SLOT을 Connect한다
//member variable
QString tempMemo_ = {};
QTextEdit* memoEdit = dialog_->findChild<QTextEdit*>(toString(ControlID::editMemo));
if (memoEdit->toPlainText().length() > 256)//set maxlength 256
{
disconnect(memoEdit, SIGNAL(textChanged()), this, SLOT(slotValueChanged_memo())));
QTextCursor currentCursor = memoEdit->textCursor();
int pos = currentCursor.position();
memoEdit->setPlainText(tempMemo_);
currentCursor.setPosition(pos - 1, QTextCursor::MoveMode::MoveAnchor);
memoEdit->setTextCursor(currentCursor);
connect(memoEdit, SIGNAL(textChanged()), this, SLOT(slotValueChanged_memo())));
}
else
{
//keep text at last input
tempMemo_ = memoEdit->toPlainText();
}
RECENT COMMENT