Development/Tutorials/Qt4 Ruby Tutorial/Chapter 2/fi: Difference between revisions
Centerlink (talk | contribs) (Created page with "=== Harjoitukset ===") |
Centerlink (talk | contribs) (Created page with "Yritä muuttaa ikkunan kokoa. Sulje sovellus napsauttamalla painiketta.") |
||
Line 75: | Line 75: | ||
=== Harjoitukset === | === Harjoitukset === | ||
Yritä muuttaa ikkunan kokoa. Sulje sovellus napsauttamalla painiketta. | |||
Are there any other signals in [http://doc.qt.nokia.com/latest/qpushbutton.html Qt::PushButton] you can connect to quit? [Hint: The [http://doc.qt.nokia.com/latest/qpushbutton.html Qt::PushButton] inherits most of its functionality from [http://doc.qt.nokia.com/latest/qabstractbutton.html Qt::AbstractButton].] | Are there any other signals in [http://doc.qt.nokia.com/latest/qpushbutton.html Qt::PushButton] you can connect to quit? [Hint: The [http://doc.qt.nokia.com/latest/qpushbutton.html Qt::PushButton] inherits most of its functionality from [http://doc.qt.nokia.com/latest/qabstractbutton.html Qt::AbstractButton].] | ||
[[Category:Ruby]] | [[Category:Ruby]] |
Revision as of 07:39, 22 September 2011
Development/Tutorials/Qt4 Ruby Tutorial/Chapter 2
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
Tutorial Series | Qt4 Ruby -oppikurssi |
Previous | Oppikurssi 1 - Hei Maailma! |
What's Next | Oppikurssi 3 - Perhearvot |
Further Reading | n/a |
Poistuu kutsuttaessa
Tiedostot:
Yleistä
Sen jälkeen kun loimme ikkunan kappaleessa 1, jatkamme nyt saamalla sovelluksen poistumaan oikein silloin kun käyttäjä käskee sen tehdä niin.
Käytämme myös kirjasimia, jotka ovat jännittävämpiä kuin oletuskirjasimet.
require 'Qt4'
app = Qt::Application.new(ARGV)
quit = Qt::PushButton.new('Poistu')
quit.resize(75, 30)
quit.setFont(Qt::Font.new('Times', 18, Qt::Font::Bold))
Qt::Object.connect(quit, SIGNAL('clicked()'), app, SLOT('quit()'))
quit.show()
app.exec()
Läpikäynti rivi riviltä
quit = Qt::PushButton.new('Poistu')
Tällä kertaa painike sanoo Poistu ja se on tarkalleen, mitä ohjelma tekee kun käyttäjä napsauttaa painiketta.
quit.resize(75, 30)
We've chosen another size for the button since the text is a bit shorter than "Hello world!". We could also have used Qt::FontMetrics to set right size, or let Qt::PushButton choose a reasonable default.
quit.setFont(Qt::Font.new('Times', 18, Qt::Font::Bold))
Here we choose a new font for the button, an 18-point bold font from the Times family. It is also possible to change the default font for the entire application, using Qt::Application::setFont().
Qt::Object.connect(quit, SIGNAL('clicked()'), app, SLOT('quit()'))
Qt::Object::connect() is perhaps the most central feature of Qt. Note that connect() in this context is a static function in Qt::Object. Do not confuse it with the connect() function in the Berkeley socket library.
This connect() call establishes a one-way connection between two Qt objects (objects that inherit Qt::Object, directly or indirectly). Every Qt object can have both signals (to send messages) and slots (to receive messages). All widgets are Qt objects, since they inherit Qt::Widget, which in turn inherits Qt::Object.
Here, the clicked() signal of quit is connected to the quit() slot of app, so that when the button is clicked, the application quits.
The Signaalit ja Välit-dokumentaatio kuvailee tämän aiheen yksityiskohtaisesti.
Sovelluksen suorittaminen
When you run this program, you will see an even smaller window than in Chapter 1, filled with an even smaller button.
Harjoitukset
Yritä muuttaa ikkunan kokoa. Sulje sovellus napsauttamalla painiketta.
Are there any other signals in Qt::PushButton you can connect to quit? [Hint: The Qt::PushButton inherits most of its functionality from Qt::AbstractButton.]