You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, October 27th 2010, 1:26pm

Cross platform Edit (F2) key

Hi, I'm new to Qt, so please excuse me if I'm asking dummy question.
I'm creating an application where I want to react to edit key (F2) by opening a dialog box for editing items.

Currently I use this code:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
void ConnectDialog::keyReleaseEvent(QKeyEvent *event)
{
	switch(event->key()){
	case Qt::Key_F2: //line of interest
    	editConnection();
    	break;
	case Qt::Key_Delete:
    	deleteConnection();
    	break;
	default:
    	QDialog::keyReleaseEvent(event);
	}
}


However as my colleagues that use Mac told me, Enter key is more appropriate for editing items on Mac.
How should I change this code so that it works appropriately on every supported platform?

Thanks in advance!

tomasstr

Beginner

  • "tomasstr" is male

Posts: 35

Location: Vilnius, Lithuania

  • Send private message

2

Wednesday, October 27th 2010, 7:07pm

One way to do that is to use #if defined. Something like this

Source code

1
2
3
4
5
6
7
8
9
10
...
switch(event->key()){
#ifdef Q_WS_MAC
  case Qt::Key_Enter:
#else
  case Qt::Key_F2:
#endif
  editConnection();
  break;
  ...


This way code compiled on Mac will have an Enter and for other os'es - F2 used for edit.

P.S. Please check actual values of Q_xx_xxx for OS's you need.

3

Thursday, October 28th 2010, 8:39am

Ok, thank you for the answer!