add copy, past and cut for plainTextedit
This commit is contained in:
parent
75f9928957
commit
516d432bdd
@ -514,10 +514,17 @@ void MainWindow::on_actionopenFile_triggered()
|
||||
void MainWindow::copyText(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(focused);
|
||||
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
|
||||
|
||||
if(lineEdit) {
|
||||
if (lineEdit && !lineEdit->selectedText().isEmpty()) {
|
||||
Clipboard->setText(lineEdit->selectedText());
|
||||
} else if (plainTextEdit) {
|
||||
QTextCursor cursor = plainTextEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
Clipboard->setText(cursor.selectedText());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::on_actionEditCopy_triggered()
|
||||
@ -528,12 +535,12 @@ void MainWindow::on_actionEditCopy_triggered()
|
||||
void MainWindow::pastText(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(focused);
|
||||
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
|
||||
|
||||
if(lineEdit) {
|
||||
QString text = lineEdit->text();
|
||||
int pos = lineEdit->cursorPosition();
|
||||
text.insert(pos, Clipboard->text());
|
||||
lineEdit->setText(text);
|
||||
if (lineEdit) {
|
||||
lineEdit->insert(Clipboard->text());
|
||||
} else if (plainTextEdit) {
|
||||
plainTextEdit->insertPlainText(Clipboard->text());
|
||||
}
|
||||
}
|
||||
void MainWindow::on_actionEditPaste_triggered()
|
||||
@ -545,14 +552,20 @@ void MainWindow::on_actionEditPaste_triggered()
|
||||
void MainWindow::cutText(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(focused);
|
||||
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
|
||||
|
||||
if(lineEdit) {
|
||||
QString text = lineEdit->text();
|
||||
if (lineEdit) {
|
||||
QString selectedText = lineEdit->selectedText();
|
||||
int pos = lineEdit->selectionStart();
|
||||
text.remove(pos, selectedText.length());
|
||||
Clipboard->setText(selectedText);
|
||||
lineEdit->setText(text);
|
||||
if (!selectedText.isEmpty()) {
|
||||
Clipboard->setText(selectedText);
|
||||
lineEdit->del();
|
||||
}
|
||||
} else if (plainTextEdit) {
|
||||
QTextCursor cursor = plainTextEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
Clipboard->setText(cursor.selectedText());
|
||||
cursor.removeSelectedText();
|
||||
}
|
||||
}
|
||||
}
|
||||
void MainWindow::on_actionEditCut_triggered()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user