[ Pobierz całość w formacie PDF ]
name=0, WFlags f=0 )
QLabel ( const QString & text, QWidget *
parent, const char * name=0, WFlags f=0 )
QLabel ( QWidget * buddy, const QString &,
QWidget * parent, const char * name=0,
WFlags f=0 )
As you can see from the code, I used the second
line from this selection of constructors. This allows
us set the text of the QLabel instead of using
setText() to set it after we create the object. You
can see that the second argument with the
second constructor is the parent of the type
QWidget *. A QWidget is a fundamental class in
Qt that can act as a parent for other items.
Typically the QWidget is used as an area of screen
that can hold other widgets.
The QTextBrowser Widget displaying a HTML page
An example of using a QWidget as a parent would
be:
create this QLabel on line 16 and use this we are
1 #include
using the QWidget as a parent. The only other
2 #include
difference is that I set the geometry of the QLabel
3
on line 17, and I set the Geometry of the
4 class LabWidget : public QWidget
LabWidget object (which is QWidget derived) on
5 {
line 26.
6 public:
7 LabWidget( QWidget *parent=0,
const char *name=0 ); On we go next month...
8 };
Well that s all we have time for this month, but
9
next month I will be looking at some of the other
10 LabWidget::LabWidget( QWidget
*parent, const char *name ) widgets and layout managers to make your
11 : QWidget( parent, name )
interfaces more streamlined. Stay tuned folks...
12 {
13 setMinimumSize( 200, 120 );
Compiling Qt Programs
14 setMaximumSize( 200, 120 );
15
Compiling Qt programs is similar to compiling
16 QLabel * lab = new QLabel( Hello
other software using libraries on Linux
World , this, label , 0);
machines. It is suggested that you read the
17 lab->setGeometry( 80, 50, 75, 30
); gcc manual and HOWTO s at
18 }
http://www.linuxdoc.org/. Typically you need
19
to make sure you link with -lqt and other
20 int main( int argc, char **argv )
XFree86 linker flags (these may include -lXext
21 {
-lX11).
22 QApplication a( argc, argv );
23
24 LabWidget myWidg;
25 myWidg.setGeometry( 200, 100,
200, 120 );
26 a.setMainWidget( &myWidg );
27 myWidg.show();
28 return a.exec();
29 }
In this example the application basically behaves
pretty much the same, although I created a class
called LabWidget. This LabWidget class inherits
from QWidget on line 4, so therefore when we
14 · 2001 LINUX MAGAZINE 41
[ Pobierz całość w formacie PDF ]