PDA

View Full Version : Using Short cut keys



joseph
12th March 2008, 13:28
I use Open Suse10.2.

I have an "Undo" menu which has a ctr+z short key.

When there are no more items to delete from my MainWindow widget,then i disable the menu and associated action (undoId->setEnabled(false);)

But the short cut key(ctr+Z) is still enabled.

Here is the snapshot of my program.


Chemedit::Chemedit(QWidget *parent):QMainWindow( parent )
{
_undoIcon = new QIcon("/home/rajeev/niveditha/trialofevent/src/Undo.png" );
menubar=QMainWindow::menuBar ();
edit = new QMenu();

edit = menuBar()->addMenu(tr("&Feby _ Menu"));

undoId = edit->addAction("Action_undo ]", this , SLOT(undo()),QKeySequence::Undo);
edit->addAction("Enable_Undo",this,SLOT(enableUndo()) );
undoId->setToolTip( tr("Undo last drawing") );
undoId->setStatusTip(tr("Undo last drawing"));
undoId->setEnabled(true);

}
void Chemedit::disableundo()
{
QMessageBox::information( this ," In Chemedit",
"To inform you that we are DISABLING the Chemedit::undo()" );
undoId->setEnabled(false);
}


Thank You.

wysota
12th March 2008, 21:07
Do you use the Qt undo/redo framework? If so, it should update the action automatically.

archanasubodh
13th March 2008, 06:06
No we do not use the QT Undo/Redo framework.

wysota
13th March 2008, 08:36
Which version of Qt are you using?

archanasubodh
13th March 2008, 09:54
We are using Qt 4.2.2.

fanat9
13th March 2008, 10:11
Try to disable action, but not only menu.

joseph
13th March 2008, 11:16
Do you use the Qt undo/redo framework? If so, it should update the action automatically.

Please see the below code, forget about whatever i have explained in previous threads..

Problem what i am facing is ...
=>i am using Qt::Ctrl + Qt::key_z for UNDOing.
=> I am passing these QKeysequence in the function

addAction( ..., ..., ..., Qt::Ctrl + Qt::key_z )
=> In some cases i am disabling the action(QAction). so the key sequence also suppose to be disabled.
=> In windows keysequence is DISABLING along with the action DISABLING , but in Linux the keysequence is ACTIVE even after the action( QAction) is disabled..
WHY ....????

Here is the small code snippt.

wysota
13th March 2008, 14:04
Try this and see if it works:

undoId = new QAction(this);
undoId->setText("Action_undo");
undoId->setShortcut(QKeySequence("CTRL+Z"));
edit->addAction(undoId);
connect(undoId, SIGNAL(triggered()), this, SLOT(undo()));

joseph
14th March 2008, 10:22
Try this and see if it works:

undoId = new QAction(this);
undoId->setText("Action_undo");
undoId->setShortcut(QKeySequence("CTRL+Z"));
edit->addAction(undoId);
connect(undoId, SIGNAL(triggered()), this, SLOT(undo()));

Wysota,
Even you solution is not working .
My question is why it's working ( as per expectation or document ) in Windows and not working in Linux ...?


Is it a bug of qt4.x

thanks in advance

wysota
14th March 2008, 10:48
No, I doubt that. I'd rather suspect you create the action two times or something like that. I'm not convinced there is even a QShortcut object created when assigning the shortcut.

archanasubodh
17th March 2008, 05:32
No, I doubt that. I'd rather suspect you create the action two times or something like that. I'm not convinced there is even a QShortcut object created when assigning the shortcut.



See the below code and please tell me where is the fault..



************************************************** *************************/


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <Qt>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QKeySequence>
#include <QString>
#include<QShortcut>

#include <QMessageBox>
#include <QApplication>

#include "MyMainWindow.h"



Chemedit::Chemedit(QWidget *parent):QMainWindow( parent )
{
menubar=QMainWindow::menuBar ();
edit = new QMenu();
Q_CHECK_PTR( edit );
edit = menuBar()->addMenu(tr("&Feby _ Menu"));

undoId = edit->addAction("Action_undo ]", this , SLOT(undo()),Qt::CTRL+Qt::Key_Z);
disableUndo = edit->addAction("Disable_Undo",this,SLOT(disableundo()));
EnableUndo = edit->addAction("Enable_Undo",this,SLOT(enableUndo()) );
undoId->setEnabled(true);

}
void Chemedit::disableundo()
{
QMessageBox::information( this ," In Chemedit",
"To inform you that we are DISABLING the Chemedit::undo()" );
undoId->setEnabled(false);
}
void Chemedit::enableUndo()
{
QMessageBox::information( this ," In Chemedit",
"To inform you that we are ENABLING the Chemedit::undo()" );
undoId->setEnabled(true);
}
void Chemedit::undo()
{
QMessageBox::information( this ," In Chemedit", "Chemedit::undo()" );
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Chemedit mainWin;
mainWin.show();
return app.exec();

}

Gopala Krishna
17th March 2008, 18:06
IIRC this is a qt bug. Have you tried your program with qt 4.3 + ?

wysota
17th March 2008, 18:45
Works fine for me in Qt 4.3 and 4.4.

Gopala Krishna
18th March 2008, 18:50
Works fine for me in Qt 4.3 and 4.4.

That means it is indeed qt 4.2.* bug. Unfortunately i couldn't find a related entry in task tracker.

wysota
18th March 2008, 19:34
That means it is indeed qt 4.2.* bug.

I'm not so sure. Can someone test it against 4.2?