It sounds like you have set up your actions incorrectly, so instead of it behaving the way you want it to, it's behaving the way you've told it to.
Could you please tell what I am doing wrong with this setup:
mainwindow.h:
{
Q_OBJECT
public:
~MainWindow();
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
QLineEdit *title;
QLineEdit *name;
QLineEdit *surname;
};
To copy to clipboard, switch view to plain text mode
mainwindow.cpp:
MainWindow
::MainWindow(QWidget *parent
){
vbox->addWidget(title);
vbox->addWidget(name);
vbox->addWidget(surname);
w->setLayout(vbox);
this->setCentralWidget(w);
QMenu *undoMenu
= menuBar
()->addMenu
("Edit");
// undoMenu->addAction("Undo", this, SLOT(undo()), QKeySequence::Undo); // does nothing
undoMenu
->addAction
("Undo", title,
SLOT(undo
()),
QKeySequence::Undo);
// undoes only title}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QVBoxLayout *vbox = new QVBoxLayout();
title = new QLineEdit();
vbox->addWidget(title);
name = new QLineEdit();
vbox->addWidget(name);
surname = new QLineEdit();
vbox->addWidget(surname);
QWidget *w = new QWidget(this);
w->setLayout(vbox);
this->setCentralWidget(w);
QMenu *undoMenu = menuBar()->addMenu("Edit");
// undoMenu->addAction("Undo", this, SLOT(undo()), QKeySequence::Undo); // does nothing
undoMenu->addAction("Undo", title, SLOT(undo()), QKeySequence::Undo); // undoes only title
}
To copy to clipboard, switch view to plain text mode
And thanks for the QSignalMapper link, I will have a look at it...
Bookmarks