Problem with QTextEdit copy function after assigning it a QAction
-
I have a
QTextEditand aQPlainTextEditin the same widget. They cope with each others well with the "copy-to-clipboard" function. When I make a text selection and pressed Ctrl+C, the corresponded TextEdit would do the copying.But then I'm having trouble trying to add a button for the command. I created a
QAction * m_pActionCopyand connect it to a slot// m_textEditor created from QPlainTextEdit // m_lineText created from QTextEdit void MainWindow::slotCopy() { m_textEditor->copy(); }Now the
QPlainTextEditis taking control of the copy function. When I highlight text and copy from theQTextEdit, the program was still listening to theQPlainTextEditwidget. How do I fix this? -
Hi,
What type of button ?
How are you creating your action ? -
The button is a push button. I also added the action into a menu.
QAction * m_pActionCopy = new QAction(icon, "Copy", this); m_pActionCopy->setShortcuts(QKeySequence::Copy); m_pActionCopy->setCheckable(false); connect(m_pActionCopy, SIGNAL(triggered()), this, SIGNAL(slotCopy())); pEditMenu->addAction(m_pActionCopy); -
The button is a push button. I also added the action into a menu.
QAction * m_pActionCopy = new QAction(icon, "Copy", this); m_pActionCopy->setShortcuts(QKeySequence::Copy); m_pActionCopy->setCheckable(false); connect(m_pActionCopy, SIGNAL(triggered()), this, SIGNAL(slotCopy())); pEditMenu->addAction(m_pActionCopy);@lansing
I'm afraid I do not understand what you are saying at all. But your slot hasm_textEditor->copy();, so it will always copy from yourQPlainTextEdit. If you want something to copy fromQTextEdit, you will need a a slot containingm_lineText->copy();. -
@lansing
I'm afraid I do not understand what you are saying at all. But your slot hasm_textEditor->copy();, so it will always copy from yourQPlainTextEdit. If you want something to copy fromQTextEdit, you will need a a slot containingm_lineText->copy();.@JonB said in Problem with QTextEdit copy function after assigning it a QAction:
If you want something to copy from QTextEdit, you will need a a slot containing m_lineText->copy();.
ah, now I maybe understand what @lansing want to do.
void MainWindow::slotCopy() { if( focusWidget() == m_textEditor) m_textEditor->copy(); else if( focusWidget() == m_lineEdit) m_lineEdit->copy(); } -
@JonB said in Problem with QTextEdit copy function after assigning it a QAction:
If you want something to copy from QTextEdit, you will need a a slot containing m_lineText->copy();.
ah, now I maybe understand what @lansing want to do.
void MainWindow::slotCopy() { if( focusWidget() == m_textEditor) m_textEditor->copy(); else if( focusWidget() == m_lineEdit) m_lineEdit->copy(); }