⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hello.cpp

📁 linux下的Qt编程源程序
💻 CPP
字号:
#include "hello.h"#include <qpushbutton.h>#include <qtimer.h>#include <qpainter.h>#include <qpixmap.h>/*  Constructs a Hello widget. Starts a 40 ms animation timer.*/Hello::Hello( const char *text, QWidget *parent, const char *name )    : QWidget(parent,name), t(text), b(0){            optionsFormLayout = new QVBoxLayout(this ,11,6);    chartTypeLayout = new QHBoxLayout( 0, 0, 6 );        fontLayout = new QHBoxLayout(0,0,6);        sysName=new  QPushButton("&Font...",this);         fontLayout->addWidget( sysName );    QTimer *timer = new QTimer(this);    connect( timer, SIGNAL(timeout()), SLOT(animate()) );    timer->start( 40 );    resize( 260, 130 );}/*  This private slot is called each time the timer fires.*/void Hello::animate(){    b = (b + 1) & 15;    repaint( TRUE );}/*  Handles mouse button release events for the Hello widget.  We emit the clicked() signal when the mouse is released inside  the widget.*/void Hello::mouseReleaseEvent( QMouseEvent *e ){    if ( rect().contains( e->pos() ) )        emit clicked();}/*  Handles paint events for the Hello widget.  Flicker-free update. The text is first drawn in the pixmap and the  pixmap is then blt'ed to the screen.*/void Hello::paintEvent( QPaintEvent * ){    static int sin_tbl[16] = { 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38};    //static int sin_tbl[16]={ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};        if ( t.isEmpty() )        return;    // 1: Compute some sizes, positions etc.    QFontMetrics fm = fontMetrics();    int w = fm.width(t) + 20;    int h = fm.height() * 2;    int pmx = width()/2 - w/2;    int pmy = height()/2 - h/2;    // 2: Create the pixmap and fill it with the widget's background    QPixmap pm( w, h );    pm.fill( this, pmx, pmy );    // 3: Paint the pixmap. Cool wave effect    QPainter p;    int x = 10;    int y = h/2 + fm.descent();    int i = 0;    p.begin( &pm );    p.setFont( font() );    while ( !t[i].isNull() ) {        int i16 = (b+i) & 15;        p.setPen( QColor((15-i16)*16,255,255,QColor::Hsv) );        p.drawText( x, y-sin_tbl[i16]*h/800, t.mid(i,1),1 );        x += fm.width( t[i] );        i++;    }    p.end();    // 4: Copy the pixmap to the Hello widget    bitBlt( this, pmx, pmy, &pm );} /****************************************************************************** $Id:  qt/main.cpp   3.0.5   edited Oct 12 2001 $**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of an example program for Qt.  This example** program may be used, distributed and modified without limitation.*******************************************************************************///#include "hello.h"#include <qapplication.h>/*  The program starts here. It parses the command line and builds a message  string to be displayed by the Hello widget.*/int main( int argc, char **argv ){    QApplication a(argc,argv);    QString s;        /*    QPushButton quit( "Quit", 0 );    quit.resize( 75, 30 );    quit.setFont( QFont( "Times", 18, QFont::Bold ) );    QObject::connect( &quit, SIGNAL(clicked()), &a, SLOT(quit()) );    */   for ( int i=1; i<argc; i++ ) {        s += argv[i];        if ( i<argc-1 )            s += "  ";    }        if ( s.isEmpty() )        s = "Hello, World";    Hello h( s );#ifndef QT_NO_WIDGET_TOPEXTRA   // for Qt/Embedded minimal build    h.setCaption( "Qt says hello" );#endif    QObject::connect( &h, SIGNAL(clicked()), &a, SLOT(quit()) );  //  h.setFont( QFont("Helvetica",32,QFont::Bold) );     h.setFont( QFont("times",36,QFont::Bold) );         // default font    h.setBackgroundColor( Qt::yellow );                  // default bg color    h.setGeometry(300,150,400,300);    a.setMainWidget( &h );       h.show();    return a.exec();} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -