Qt default button on mac - qt

Mac have a capability to specify two default buttons, one activated by return and other by spacebar. One clear example is when you press power button on mac. It gives you a dialog box with quiet a few buttons, in which it shutdown is default for return key and restart is default for spacebar key. Is it possible to achieve such effect in Qt?

Yes.
Use QPushButton. On the "default" button use setDefault and setAutoDefault() to make them appear as a default button.
http://doc.trolltech.com/4.7/qpushbutton.html#default-prop
To handle the escape key (and possibly even the return key), you must set the shortcuts for each button to associate them with a corresponding key. It's easy to do that using Qt Creator/Designer.

Related

How to intercept / modify excape key functionality in Qt

I am trying to fix a bug in a Qt app which I did not write. The window changes the background color of the entire window to red and puts up some buttons, dialog boxes, etc. When the escape key is pushed, the boxes and buttons go away, leaving an empty red screen. The Cancel button does the right thing in returning to the previous window. I think I need to somehow be notified of when the escape key is pushed, and then call the same function as the cancel pushbutton does. Hopefully, I can limit the scope of this special action to when the problem window is up. I am an experienced programmer but a complete Qt newbie. This app is purely C++. To my knowledge, it does not appear to use any QML. I am still searching through the Qt online documentation, but any suggestions / examples are appreciated.
This depends a lot on your specific Qt version and setup of your application. That said, I'll take a shot at helping. In the class where you're trying to intercept the escape key press, assuming it's inheriting QObject, simply override the virtual function eventFilter. Inside your overridden instance of eventFilter, check that the QEvent type is a QEvent::KeyPress, and then check whether the key of that KeyPress is the escape key, and handle as needed.
Be sure that you pass the event out of your function, else you'll see your overridden function eat all events. If you explicitly want the event to be "eaten", simply do not return it from your function. For specifics and examples, check out documentation of QObject::eventFilter().

How to implement only emoji keyboard for Entry?

I would like to implement Custom Entry (Xamarin.forms) when the user focus the Entry, device will show Emoji keyboard.
Short answer
Unfortunately it is impossible without creating your own keyboard, due to Android and iOS platform limitations.
Long answer
Default behaviour on iOS is to show the emoji keyboard icon in the bottom of the keyboard. So it is only one tap away from the user:
Default behaviour on Android is seems to be slightly different and the emoji keyboard is hidden by default:
Luckily, it is very easy to place the emoji keyboard icon by setting the InputType to Android.Text.InputTypes.TextVariationShortMessage | Android.Text.InputTypes.ClassText:
If you are still looking to show the emoji keyboard by default, I am afraid you will have to implement your own keyboard view. Depend on your needs you could add few emojis as buttons and etc.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/entry#customizing-the-keyboard
Customizing the Keyboard
The keyboard that's presented when users interact with an Entry can be set programmatically via the Keyboard property, to one of the following properties from the Keyboard class:
Chat – used for texting and places where emoji are useful.
Default – the default keyboard.
Email – used when entering email addresses.
Numeric – used when entering numbers.
Plain – used when entering text, without any KeyboardFlags specified.
Telephone – used when entering telephone numbers.
Text – used when entering text.
Url – used for entering file paths & web addresses.
This can be accomplished in XAML as follows:
<Entry Keyboard="Chat" />
The equivalent C# code is:
var entry = new Entry { Keyboard = Keyboard.Chat };

How to capture Tab Key in Qt widget

I want to implement my own sequence for changing the focus of the active child widget using the Tab key. How to capture the Tab Key press event? I am using Qt5.2
If you want to change focus with Tab , you don't need to do those works, Qt has it as a feature.
First: set the desired widgets to be Qt::TabFocus or Qt::StrongFocus by QWidget::setFocusPolicy( Qt::FocusPolicy policy )
For example, if you want to rotate between 3 QLineEdit and 1 QCombobox, you have to assure that their focus policy have been set right. (Normally either Qt::TabFocus or Qt::StrongFocus will be set as default, but sometimes you might want to escape some widgets from being tabbed)
Second: go to designer mode and click "Edit Tab Order" to enter the tab-order editing mode
Third: After seeing the numbers, click on them until you got the desired sequence order.
(Picture from Qt official site)
Have a mouse press event or a event filter, get to the point where you have a QKeyEvent
Then only do something if tab was pressed
key_event->button() == Qt::Key_Tab

Detect arrow key input in qt

How would I detect the pressing of one of the arrow keys in qt? Also, would the application still detect them if it is minimized?
How would I detect the pressing of one of the arrow keys in qt?
By handling the key press event in the top most widget in the hierarchy. See the list of key codes, the Qt::Left - Qt::Down range is what you're interested in.
Also, would the application still detect them if it is minimized?
No. It would detect them only if it had the keyboard's focus, which is not the case when minimized. You can't set up global hotkeys in a cross-platform fashion in Qt.

Flex: Simulate key press

I'm creating a virtual keyboard for a touchscreen Flex app and i'm trying to simulate a key press by dispatching a KeyboardEvent. I've written a handler function to listen for the event and act accordingly. So far so good... but it's starting to get complicated as i have to manage the focused textInputs (easy), the cursor position in those fields (not to so easy), etc.
Now, if only there was a way to actually dispatch a KeyboardEvent that Flex would actually interpret as a genuine key press all those issues would be gone... Is that possible?
The TextInput does not use KeyboardEvent/TextEvent for text input, it uses internal Flash TextField objects that interact with the Flash Player / Keyboard.
The KeyboardEvent are used to enable notification of the Keyboard Event that occured.
To simulate a keyboard, you will need to create a class that upon recieving a KeyboardEvent will modify the text property of a TextInput and the cursor position accordingly.
Alex Harui has written a similar post about this FlexCoders Post

Resources