Results 1 to 4 of 4

Thread: emitting a signal with no button?

  1. #1
    Join Date
    Oct 2010
    Posts
    58
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default emitting a signal with no button?

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: emitting a signal with no button?

    Read about QAction.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    kja (9th December 2010)

  4. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: emitting a signal with no button?

    You can also override the QWidget::KeyPressEvent(...).

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: emitting a signal with no button?

    Quote Originally Posted by kja View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. static function emitting signal
    By wagmare in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2010, 08:34
  2. Problem emitting a signal
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2009, 00:56
  3. Emitting signal from DLL to EXE
    By Miihkali in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2009, 08:32
  4. Emitting signal causes CRASH
    By navi1084 in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2009, 16:17
  5. cost of emitting signal
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 29th November 2006, 08:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.