1 /***************************************************************************
2 displaynumber.cpp - description
4 begin : Sun Feb 23 2003
5 copyright : (C) 2003 by Michael v.Ostheim
6 email : ostheimm@users.berlios.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
19 #include <qfontmetrics.h>
24 #include "displaynumber.h"
26 DisplayNumber::DisplayNumber(QWidget
*parent
, int digits
, int prec
)
32 setFrameStyle(QFrame::Panel
| QFrame::Sunken
);
33 setBackgroundRole(QPalette::Base
);
34 setAlignment(Qt::AlignCenter
);
35 setFocusPolicy(Qt::NoFocus
);
38 DisplayNumber::~DisplayNumber(){
41 void DisplayNumber::setFont( const QFont
& f
) {
46 void DisplayNumber::setWidth(int digits
) {
47 QFontMetrics
fm(font());
48 QString
s("0123456789.+-");
49 int width
= 0, charWidth
=0;
51 for (int i
= 0; i
< 11; i
++, width
= fm
.width(s
[i
]))
52 charWidth
= (width
> charWidth
) ? width
: charWidth
;
55 setMinimumWidth( dg
* charWidth
+ charWidth
/2 );
58 void DisplayNumber::setNum(double num
) {
60 setText(text
.setNum(num
, 'f', precision
));
64 #include "displaynumber.moc"