Results 1 to 9 of 9

Thread: enable shortcuts using Designer

  1. #1
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default enable shortcuts using Designer

    Hi all,

    I would like to use shortcuts in my GUI application. In the Big Book (C++-GUI Programming with Qt4 - 1st ed) I found an example, which works very well, in which the author suggests to enable the shortcut simply by declarating like this:

    findButton = new QPushButton(tr("&Find"));

    But in this example we don't use the Designer. My application on the other hand was created with the help of the Designer embedded into QtCreator. I tryed to define the text variable like "&next" (ect), and in the designer I can see the underlined letters, but they disappear when I try to run the program, as if it has never been set.

    Thanks for future help
    Szilvi
    Szilvi

  2. #2
    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: enable shortcuts using Designer

    It's not because you use Designer but rather because you use a label. Labels need to be associated with other widgets using the "buddy" mechanism for accelerators to 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.


  3. #3
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: enable shortcuts using Designer

    No, the goal is to use the shortcuts for my buttons. Maybe this printscreen helps to see better what I might misundertand.
    Szilvi

  4. #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: enable shortcuts using Designer

    When the program is running press "alt" (or was it "ctrl"?) and see if you get your underscore. If it doesn't work, post your ui file.
    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.


  5. #5
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: enable shortcuts using Designer

    I tried that alt-thing, because I've read that in some description, but that does not work.

    xml Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>kepMegjelenito</class>
    4. <widget class="QWidget" name="kepMegjelenito">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>800</width>
    10. <height>600</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>kepMegjelenito</string>
    15. </property>
    16. <property name="autoFillBackground">
    17. <bool>false</bool>
    18. </property>
    19. <widget class="QLabel" name="tartalomLabel">
    20. <property name="geometry">
    21. <rect>
    22. <x>20</x>
    23. <y>330</y>
    24. <width>361</width>
    25. <height>20</height>
    26. </rect>
    27. </property>
    28. <property name="text">
    29. <string>Itt lesz majd a file tartalma.</string>
    30. </property>
    31. </widget>
    32. <widget class="QLabel" name="infoLabel">
    33. <property name="geometry">
    34. <rect>
    35. <x>60</x>
    36. <y>370</y>
    37. <width>491</width>
    38. <height>16</height>
    39. </rect>
    40. </property>
    41. <property name="text">
    42. <string>Az a cĂ©l, hogy a jobb oldali listában file-ok legyenek, amiknek elsĹ‘ sorát a bal oldalon megjelenĂ*tem.</string>
    43. </property>
    44. </widget>
    45. <widget class="QPushButton" name="closeButton">
    46. <property name="geometry">
    47. <rect>
    48. <x>10</x>
    49. <y>10</y>
    50. <width>141</width>
    51. <height>61</height>
    52. </rect>
    53. </property>
    54. <property name="text">
    55. <string>&amp;KLĂ“Z</string>
    56. </property>
    57. </widget>
    58. <widget class="QWidget" name="layoutWidget">
    59. <property name="geometry">
    60. <rect>
    61. <x>630</x>
    62. <y>30</y>
    63. <width>161</width>
    64. <height>321</height>
    65. </rect>
    66. </property>
    67. <layout class="QVBoxLayout" name="verticalLayout">
    68. <item>
    69. <widget class="QPushButton" name="kvtButton">
    70. <property name="text">
    71. <string>&amp;Valasztok Konyvtarat</string>
    72. </property>
    73. </widget>
    74. </item>
    75. <item>
    76. <widget class="QLabel" name="listLabel">
    77. <property name="text">
    78. <string>A kiválasztott kvt tartalma:</string>
    79. </property>
    80. </widget>
    81. </item>
    82. <item>
    83. <widget class="QListWidget" name="myListWidget"/>
    84. </item>
    85. </layout>
    86. </widget>
    87. <widget class="QLabel" name="staticPicLabel">
    88. <property name="geometry">
    89. <rect>
    90. <x>180</x>
    91. <y>10</y>
    92. <width>141</width>
    93. <height>91</height>
    94. </rect>
    95. </property>
    96. <property name="text">
    97. <string>TextLabel</string>
    98. </property>
    99. </widget>
    100. <widget class="QLabel" name="imageLabel">
    101. <property name="geometry">
    102. <rect>
    103. <x>40</x>
    104. <y>110</y>
    105. <width>411</width>
    106. <height>201</height>
    107. </rect>
    108. </property>
    109. <property name="text">
    110. <string>TextLabel</string>
    111. </property>
    112. </widget>
    113. <widget class="QPushButton" name="nextButton">
    114. <property name="geometry">
    115. <rect>
    116. <x>440</x>
    117. <y>300</y>
    118. <width>75</width>
    119. <height>23</height>
    120. </rect>
    121. </property>
    122. <property name="text">
    123. <string>&amp;next</string>
    124. </property>
    125. </widget>
    126. </widget>
    127. <layoutdefault spacing="6" margin="11"/>
    128. <resources/>
    129. <connections>
    130. <connection>
    131. <sender>closeButton</sender>
    132. <signal>clicked()</signal>
    133. <receiver>kepMegjelenito</receiver>
    134. <slot>close()</slot>
    135. <hints>
    136. <hint type="sourcelabel">
    137. <x>90</x>
    138. <y>34</y>
    139. </hint>
    140. <hint type="destinationlabel">
    141. <x>156</x>
    142. <y>11</y>
    143. </hint>
    144. </hints>
    145. </connection>
    146. <connection>
    147. <sender>myListWidget</sender>
    148. <signal>itemClicked(QListWidgetItem*)</signal>
    149. <receiver>kepMegjelenito</receiver>
    150. <slot>listaelemKivalasztva(QListWidgetItem*)</slot>
    151. <hints>
    152. <hint type="sourcelabel">
    153. <x>685</x>
    154. <y>225</y>
    155. </hint>
    156. <hint type="destinationlabel">
    157. <x>371</x>
    158. <y>36</y>
    159. </hint>
    160. </hints>
    161. </connection>
    162. <connection>
    163. <sender>myListWidget</sender>
    164. <signal>itemActivated(QListWidgetItem*)</signal>
    165. <receiver>kepMegjelenito</receiver>
    166. <slot>listaelemKivalasztva(QListWidgetItem*)</slot>
    167. <hints>
    168. <hint type="sourcelabel">
    169. <x>657</x>
    170. <y>272</y>
    171. </hint>
    172. <hint type="destinationlabel">
    173. <x>567</x>
    174. <y>198</y>
    175. </hint>
    176. </hints>
    177. </connection>
    178. </connections>
    179. <slots>
    180. <slot>listaelemKivalasztva(QListWidgetItem*)</slot>
    181. </slots>
    182. </ui>
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 6th January 2011 at 11:02.
    Szilvi

  6. #6
    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: enable shortcuts using Designer

    It seems to work fine for me, the accelerator on the "next" is shown correctly.

    This is my test application:
    Qt Code:
    1. #include "ui_tst.h"
    2. #include <QtGui>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6. QWidget w;
    7. Ui::kepMegjelenito ui;
    8. ui.setupUi(&w);
    9. w.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    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.


  7. #7
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: enable shortcuts using Designer

    I use my own class, maybe there is some difference then in the usage. I usually use the creator's templates. (I don't post here everything, just the relevant parts.)

    main.cpp:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "kepmegjelenito.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. kepMegjelenito w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    kepmegjelenito.h:
    Qt Code:
    1. #ifndef KEPMEGJELENITO_H
    2. #define KEPMEGJELENITO_H
    3.  
    4. #include <QWidget>
    5. #include (... some other included classes ...)
    6.  
    7. namespace Ui {
    8. class kepMegjelenito;
    9. }
    10.  
    11. class kepMegjelenito : public QWidget {
    12. Q_OBJECT
    13. public:
    14. kepMegjelenito(QWidget *parent = 0);
    15. ~kepMegjelenito();
    16.  
    17. private:
    18. Ui::kepMegjelenito *ui;
    19. (...)
    20.  
    21. public slots: (..)
    22.  
    23. signals:(...)
    24. };
    25.  
    26. #endif // KEPMEGJELENITO_H
    To copy to clipboard, switch view to plain text mode 

    I gues there is no point showing the other codes, there is no other file, just the form, the main, this header and the "kepmegjelenito.cpp".
    in case it is still not enough info, here is the whole work: http://szisziszilvi.lima-city.de/temp/kepMegjelenitozip (which is a normal renamed zip, I could not copy to the webspace when there was that '.' character. 8.711 k)
    Szilvi

  8. #8
    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: enable shortcuts using Designer

    Sorry, I'm not going to look through 8MB of code First of all try putting your ui into the same code I used for testing and see if it works or not.
    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.


  9. #9
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: enable shortcuts using Designer

    you're right, I was simply too stupid, no excuse... so now I changed the file to another with the same name, but without the compile outputs... 5 k sounds better, eh?
    (this is a testwork for testing some functionalities, so not a very clever code, pretty easy to reach unexpected exit, but the main goal is not that.)

    I'll try your one as well (probably just tomorrow), but I'm still interested wat's wrong with my version. might be a useful lecture

    anyway I've made now a very simple application with a single close-button, ant this feature works just as it should. I'm trying to find the key difference.
    Szilvi

Similar Threads

  1. qml key shortcuts
    By antialias_forum in forum Qt Quick
    Replies: 0
    Last Post: 22nd December 2010, 14:45
  2. Shortcuts for QActions...
    By ericV in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2009, 13:18
  3. QTabWidget: Shortcuts & Clicks
    By youkai in forum Qt Programming
    Replies: 7
    Last Post: 20th July 2009, 14:12
  4. Pb with shortcuts on Mac OS
    By mourad in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2008, 19:22
  5. Creatin Key Pad shortcuts
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 19th May 2006, 05:50

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.