Translate
Appearance
Text
This page always uses small font size
Width
AllDevelopment/Tutorials/Qt4 Ruby Tutorial/Chapter 04
Translate to Deutsch
Translation of the wiki page Development/Tutorials/Qt4 Ruby Tutorial/Chapter 01 from English (en) to ייִדיש (yi)
This tool does not work without JavaScript. JavaScript is disabled, failed to work, or this browser is unsupported.
Translations:Development/Tutorials/Qt4 Ruby Tutorial/Chapter 04/Page display title/de
Development/Tutorials/Qt4 Ruby Tutorial/Chapter 04
You need translation rights to translate messages.Get permission
Loading...
Latest updatesAll changes
Suggestions
In other languages
Need more help?Ask for more information
Translations:Development/Tutorials/Qt4 Ruby Tutorial/Chapter 04/1/de
TutorialBrowser
You need translation rights to translate messages.Get permission
Loading...
Latest updatesAll changes
Suggestions
In other languages
Need more help?Ask for more information
This example shows how to create your own widget, and describes how to control the minimum and maximum sizes of a widget.
Here we create a new class. Because this class inherits from [http://doc.qt.nokia.com/latest/qwidget.html Qt::Widget], the new class is a widget and may be a top-level window or a child widget (like the [http://doc.qt.nokia.com/latest/qpushbutton.html Qt::PushButton] in the previous chapter).
This class has only one member, a constructor (in addition to the members it inherits from [http://doc.qt.nokia.com/latest/qwidget.html Qt::Widget]). The constructor is a standard Qt widget constructor; you should always include a similar constructor when you create widgets.
The argument is its parent widget. To create a top-level window you specify '''<tt>nil</tt>''' as the parent. As you can see, this widget defaults to be a top-level window.
Like most widgets, it just passes on the '''<tt>parent</tt>''' parameter to the [http://doc.qt.nokia.com/latest/qwidget.html Qt::Widget] constructor. (If you're new to Ruby, calling '''<tt>super</tt>''' without any parameters will automatically pass on any parameters a method received to the superclass's method of the same name. ''Update'': Apparently, it's also important to leave off the parentheses — calling '''<tt>super()</tt>''' will call the superclass's method of the same name with an empty parameter list.)
Because this widget doesn't know how to handle resizing, we fix its size. In the next chapter, we will show how a widget can respond to resize event from the user.
Here we create and set up a child widget of this widget (the new widget's parent is '''<tt>self</tt>''', i.e. the '''<tt>MyWidget</tt>''' instance).
The [http://doc.qt.nokia.com/latest/qobject.html#tr QObject::tr()] function call around the string literal 'Quit' marks the string for translation, making it possible to change it at run-time based on the contents of a translation file. It is a good habit to use [http://doc.qt.nokia.com/latest/qobject.html#tr QObject::tr()] around all user-visible strings, in case you decide later to translate your application to other languages.
The [http://doc.qt.nokia.com/latest/qwidget.html#geometry-prop Qt::Widget::setGeometry()] call sets both the widget's screen position and the size. It is equivalent to calling [http://doc.qt.nokia.com/latest/qwidget.html#pos-prop Qt::Widget::move()] followed by [http://doc.qt.nokia.com/latest/qwidget.html#size-prop Qt::Widget::resize()].
The '''<tt>$qApp</tt>''' pointer is a global variable created when you '''<tt>require 'Qt'</tt>'''. It points to the application's unique [http://doc.qt.nokia.com/latest/qapplication.html Qt::Application] instance.
This program is very similar in behavior to the previous one. The difference lies in the way we have implemented it. It does behave slightly differently, however. Just try to resize it to see.
Try to add more buttons or put in widgets other than [http://doc.qt.nokia.com/latest/qpushbutton.html Qt::PushButton].
Loading messages...
0% translated, 0% reviewed
Retrieved from "https://techbase.kde.org/Special:Translate"