PDA

View Full Version : emitting a signal with no button?



kja
29th November 2010, 19:36
Hi,

Is it possible to have a signal that is emitted by a keyboard shortcut without having to create any kind of button? I have tried creating a button then making a shortcut for it and just not adding that button to my layout but when I do that the shortcut doesn't work any more.

I want to be able to push control+t on a text block in a text edit, when I use the shortcut it aligns the text block to the right side of the text edit, when I use the shortcut again I want it to move the text back to the left side.

Any ideas how to do this without having a button on my gui?

thanks

high_flyer
29th November 2010, 20:00
Read about QAction.

Zlatomir
29th November 2010, 20:12
You can also override the QWidget::KeyPressEvent(...) (http://doc.qt.nokia.com/4.7/qwidget.html#keyPressEvent).

wysota
29th November 2010, 21:33
I want to be able to push control+t on a text block in a text edit, when I use the shortcut it aligns the text block to the right side of the text edit, when I use the shortcut again I want it to move the text back to the left side.

Any ideas how to do this without having a button on my gui?
Create a QAction with a shortcut and (important!) add the action to your text edit widget. Without the last part it will not work.