Qt图形编程基础之:实验内容——使用Qt编写“Hello,World”程序
, white);
cg.setColor(QColorGroup::Background, white);
cg.setColor(QColorGroup::Shadow, black);
cg.setColor(QColorGroup::Highlight, black);
cg.setColor(QColorGroup::HighlightedText, white);
pal.setActive(cg);
cg.setColor(QColorGroup::Foreground, black);
cg.setColor(QColorGroup::Button, QColor(192, 192, 192));
cg.setColor(QColorGroup::Light, white);
cg.setColor(QColorGroup::Midlight, QColor(220, 220, 220));
cg.setColor(QColorGroup::Dark, QColor(96, 96, 96));
cg.setColor(QColorGroup::Mid, QColor(128, 128, 128));
cg.setColor(QColorGroup::Text, black);
cg.setColor(QColorGroup::BrightText, white);
cg.setColor(QColorGroup::ButtonText, black);
cg.setColor(QColorGroup::Base, white);
cg.setColor(QColorGroup::Background, white);
cg.setColor(QColorGroup::Shadow, black);
cg.setColor(QColorGroup::Highlight, black);
cg.setColor(QColorGroup::HighlightedText, white);
pal.setInactive(cg);
cg.setColor(QColorGroup::Foreground, QColor(128, 128, 128));
cg.setColor(QColorGroup::Button, QColor(192, 192, 192));
cg.setColor(QColorGroup::Light, white);
cg.setColor(QColorGroup::Midlight, QColor(220, 220, 220));
cg.setColor(QColorGroup::Dark, QColor(96, 96, 96));
cg.setColor(QColorGroup::Mid, QColor(128, 128, 128));
cg.setColor(QColorGroup::Text, black);
cg.setColor(QColorGroup::BrightText, white);
cg.setColor(QColorGroup::ButtonText, QColor(128, 128, 128));
cg.setColor(QColorGroup::Base, white);
cg.setColor(QColorGroup::Background, white);
cg.setColor(QColorGroup::Shadow, black);
cg.setColor(QColorGroup::Highlight, black);
cg.setColor(QColorGroup::HighlightedText, white);
pal.setDisabled(cg);
setPalette(pal);
QFont f(FONT());
f.setFamily("adobe-helvetica");
f.setPointSize(29);
f.setBold(TRUE);
setFont(f);
setCaption(tr(""));
/* 以下是手动添加的代码 */
t = "Hello,World";
b = 0;
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), SLOT(animate()));
timer->start(40);
}
/*
* Destroys the object and frees any allocated resources
*/
Hello::~Hello()
{
}
/* 以下至结尾是手动添加的代码 */
void Hello::animate()
{
b = (b + 1) & 15;
repaint(FALSE);
}
/*
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};
if (t.isEmpty())
eturn;
/* 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())
{
nt i16 = (b+i) & 15;
.setPen(QColor((15-i16)*16,255,255,QColor::Hsv));
wText(x, y-sin_tbl[i16]*h/800, t.mid(i,1), 1);
+= fm.width(t[i]);
+;
}
p.end();
/
- Qt图形编程基础之:嵌入式GUI简介(08-13)
- 《嵌入式Linux应用程序开发标准教程》(第2版)(09-30)
- Qt图形编程基础之:Qt/Embedded开发入门(09-13)
- REDIce-Linux--灵活的实时Linux内核(11-12)
- linux文件系统基础(02-09)
- Linux标准趋向统一(11-12)