Linux °æ (¾«»ªÇø)
·¢ÐÅÈË: tcpip (¸ß¼¶²Ý°ü), ÐÅÇø: Linux
±ê Ìâ: QT tutorial 6--------"Building Blocks Galore!"
·¢ÐÅÕ¾: ¹þ¹¤´ó×϶¡Ïã (2000Äê06ÔÂ11ÈÕ12:48:06 ÐÇÆÚÌì), תÐÅ
µÚÁùÕÂ: Building Blocks Galore!
±¾Àý×ÓÑÝʾÈçºÎ°ÑÁ½¸ö¿Ø¼þ·â×°ÓÚÒ»¸öеÄÔª¼þÄÚÒÔ¼°ÈçºÎ·½±ãµØʹÓöà¸ö¿Ø¼þ.ÎÒÃǵÚÒ
»´ÎʹÓÃ×Ô¼º ¶¨ÖÆ
µÄ¿Ø¼þ×÷Ϊ×ӿؼþ.
/****************************************************************
**
** Qt tutorial 6
**
****************************************************************/
#include
#include
#include
#include
#include
class LCDRange : public QWidget
{
public:
LCDRange( QWidget *parent=0, const char *name=0 );
protected:
void resizeEvent( QResizeEvent * );
private:
QScrollBar *sBar;
QLCDNumber *lcd;
};
LCDRange::LCDRange( QWidget *parent, const char *name )
: QWidget( parent, name )
{
lcd = new QLCDNumber( 2, this, "lcd" );
lcd->move( 0, 0 );
sBar = new QScrollBar( 0, 99, // range
1, 10, // line/page steps
0, // inital value
QScrollBar::Horizontal, // orientation
this, "scrollbar" );
connect( sBar, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)) );
}
void LCDRange::resizeEvent( QResizeEvent * )
{
sBar->setGeometry( 0, height() - 16, width(), 16 );
lcd->resize( width(), sBar->y() - 5 );
}
class MyWidget : public QWidget
{
public:
MyWidget( QWidget *parent=0, const char *name=0 );
protected:
void resizeEvent( QResizeEvent * );
private:
QPushButton *quit;
LCDRange *value[16];
};
MyWidget::MyWidget( QWidget *parent, const char *name )
: QWidget( parent, name )
{
setMinimumSize( 200, 300 );
quit = new QPushButton( "Quit", this, "quit" );
quit->setGeometry( 10, 10, 75, 30 );
quit->setFont( QFont( "Times", 18, QFont::Bold ) );
connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
for( int i = 0 ; i < 16 ; i++ )
value = new LCDRange( this );
}
void MyWidget::resizeEvent( QResizeEvent * )
{
int startx = 10;
int starty = quit->y() + quit->height() + 10;
int valueWidth = (width() - startx - 10 - 3*5)/4;
int valueHeight = (height() - starty - 10 - 3*5)/4;
for( int i = 0 ; i < 16 ; i++ )
value->setGeometry( startx + (i%4)*(5+valueWidth),
starty + (i/4)*(5+valueHeight),
valueWidth, valueHeight );
}
int main( int argc, char **argv )
{
QApplication a( argc, argv );
MyWidget w;
w.setGeometry( 100, 100, 400, 400 );
a.setMainWidget( &w );
w.show();
return a.exec();
}
ÖðÐнâÊÍ´úÂë
class LCDRange : public QWidget
{
public:
LCDRange( QWidget *parent=0, const char *name=0 );
protected:
void resizeEvent( QResizeEvent * );
private:
QScrollBar *sBar;
QLCDNumber *lcd;
};
LCDRange¿Ø¼þ·â×°ÁËÁ½¸ö¿Ø¼þ:QScrollBarºÍQLCDNumber.±Ë´ËÏ໥Áª½Ó.
LCDRange::LCDRange( QWidget *parent, const char *name )
: QWidget( parent, name )
{
lcd = new QLCDNumber( 2, this, "lcd" );
lcd->move( 0, 0 );
sBar = new QScrollBar( 0, 99, // range
1, 10, // line/page steps
0, // inital value
QScrollBar::Horizontal, // orientation
this, "scrollbar" );
connect( sBar, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)) );
}
ÕâЩ»ù±¾ÉÏÀ´Ô´ÓÚµÚÎåÕµÄMyWidgetµÄ¹¹Ô캯Êý. ΨһµÄ²»Í¬ÊÇ"lcd"·ÅÔÚÁË 0,0
×ø±ê,ÒòΪÎÒÃǶ¨ÖÆÁËÒ»¸ö
еĿؼþ,²¢ÇÒËü²»ÐèÒª±ß¿ò.Èç¹û´Î¿Ø¼þ
µÄ"ʹÓÃÕß"ÐèÒª,Ëû/Ëý¿ÉÒÔÔÚLCDRangeµÄ±ßÔµ¼ÓÉϱ߿ò.
void LCDRange::resizeEvent( QResizeEvent * )
{
sBar->setGeometry( 0, height() - 16, width(), 16 );
lcd->resize( width(), sBar->y() - 5 );
}
ÒòΪLCDRange¼´Ã»Óб߿òҲûÓÐquit°´Å¥,ËùÒÔËüµÄresizeʼþÒª±ÈMyWidgetµÄresizeʼ
þ ¼òµ¥µÄ¶à.
private:
QPushButton *quit;
LCDRange *value[16];
};
MyWidget ÏÖÔÚ°üº¬ÁËÎÒÃÇÒÑÊìϤµÄquit°´Å¥ºÍÒ»¸öÓÐ16¸öLCDRange¿Ø¼þÖ¸ÕëµÄÊý×é.
for( int i = 0 ; i < 16 ; i++ )
value = new LCDRange( this );
ÔÚMyWidgetµÄ¹¹Ô캯ÊýÖÐ,ÎÒÃÇ´´½¨ÁË16¸ö¸¸¿Ø¼þÊÇthisµÄLCDRange¿Ø¼þ.
¼Çס:µ±MyWidget¿Ø¼þÏú»Ùʱ,ÕâЩ
¿Ø¼þ»á±»Qt×Ô¶¯É¾³ý.
void MyWidget::resizeEvent( QResizeEvent * )
{
int startx = 10;
int starty = quit->y() + quit->height() + 10;
int valueWidth = (width() - startx - 10 - 3*5)/4;
int valueHeight = (height() - starty - 10 - 3*5)/4;
for( int i = 0 ; i < 16 ; i++ )
value->setGeometry( startx + (i%4)*(5+valueWidth),
starty + (i/4)*(5+valueHeight),
valueWidth, valueHeight );
}
ÔÚresizeʼþÖÐ,ÎÒÃÇÓÃÁËÒ»¸ö¼òµ¥µÄÑ»·À´ÉèÖÃÕâ16¸öLCDRange¿Ø¼þµÄ¼¸ºÎ³ß´ç.
Ê×ÏÈ,ÎÒÃÇÀ´¼ÆËãLCDRange¿Ø¼þµÄ×óÉϽǵÄλÖÃ.
ÎÒÃǸøËüÁËÒ»¸ö10ÏñËصÄ×ó±ß¿ò,²¢ÇÒÔÚquit°´Å¥µÄÉÏÃæÔ¤
ÁôÁË10ÏñËصı߿ò.(Ïê¼û×ø±êϵͳ)
È»ºó,ÎÒÃÇÀ´¼ÆËãLCDRange¿Ø¼þ¶ÔÏóµÄ³ß´ç.ÎÒÃÇÏëÓÃÒ»¸ö¾ßÓÐ10ÏñËر߿òºÍÓÐ5ÏñËؼä¸ô
´óСΪ4X4¿Ø¼þµÄÍø
¸ñ.(ÔÚÿ¸ö·½ÏòÉ϶¼ÓÐÈýÌõ5ÏñËØ¿íµÄ¼ä¸ô¿ò).
×¢Òâ,ÒòΪÎÒÃÇÊÇÓÃÕûÊý4×÷³ýÊýµÄ,ËùÒÔ»áÓÐÒ»µãÎó²î.
ÏÂÃæ,ÎÒÃÇÉèÖÃÿһ¸öLCDRange¶ÔÏóµÄ¼¸ºÎ³ß´ç.ÎÒÃÇÓÃÕûÊýÈ¡Ä£ÔËËãÀ´¼ÆËãËüÃǵÄλÖÃ,²
¢ÇÒ ÔÚÿ¸ö
LCDRange¶ÔÏó¼ä¼ÓÁËÒ»¸ö5ÏñËصı߿ò.
³ÌÐòÐÐΪ
Õâ¸ö³ÌÐòÑÝʾÁËͬʱʹÓöà¸ö¿Ø¼þÊǺܼòµ¥µÄ.ÿһ¸ö¿Ø¼þµÄÐÐΪºÍÇ°¼¸ÕµĹö¶¯ÌõÓëÒº¾
§ÏÔʾÆ÷ ÊÇÒ»ÑùµÄ.
µ±È»,²»Í¬µÄÊÇʵÏֵķ½Ê½.
Á·Ï°
¸Ä±äMyWidget¿Ø¼þÒÔÈ·±£Ã¿¸öLCDRange¿Ø¼þÊÇÕý·½ÐεÄ.
ÔÚÆô¶¯Ê±,Ϊÿ¸ö¹ö¶¯Ìõ¸³Ò»¸ö²»Í¬µÄ/Ëæ»úµÄ³õʼֵ.
ÄãÏÖÔÚ¿ÉÒÔ½øÐеÚÆßÕÂÁË.
[Ç°Ò»ÕÂ] [ºóÒ»ÕÂ] [½Ì³ÌĿ¼]
Copyright ?1999 Troll Tech
Trademarks
Qt version 1.44
¡ù À´Ô´:¡¤¹þ¹¤´ó×϶¡Ïã bbs.hit.edu.cn¡¤[FROM: tcpip.hit.edu.cn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
Ò³ÃæÖ´ÐÐʱ¼ä£º2.668ºÁÃë