I am trying to create a custom widget by reimplementing QSpingBox. The reason that I (think I) need to reimplement QSpinBox is because my values are floats not integers. So I need the spinbox to work with numbers between 1.61 and 4.0 and looking at the documentation for QSpinBox I need to reimplement mapValueToText and mapTextToValue to do this. Note this is not a plugin custom widget. Also I am using QT 3.3.4 at this time.
Here is my header file:
#include "qspinbox.h"
Q_OBJECT
public:
GammaSpinBox
(QWidget * parent
= 0,
const char * name
= 0 );
QString mapValueToText
( int value
);
int mapTextToValue( bool *ok );
};
#include "qspinbox.h"
class GammaSpinBox: public QSpinBox {
Q_OBJECT
public:
GammaSpinBox(QWidget * parent = 0, const char * name = 0 );
QString mapValueToText( int value );
int mapTextToValue( bool *ok );
};
To copy to clipboard, switch view to plain text mode
and here is my iplementation:
#include "gammaspinbox.h"
{
Q_OBJECT
public:
GammaSpinBox
(QWidget * parent
= 0,
const char * name
= 0 ) : QSpinBox(161,
400,
1, parent, name
) {
}
QString mapValueToText
( int value
) {
return QString( "%1.%2" ) // 1.61 to 4.00 .arg( value / 100 ).arg( value % 100 );
}
int mapTextToValue( bool *ok )
{
return (int) ( 100 * text().toFloat() );
}
};
#include "gammaspinbox.h"
class GammaSpinBox : public QSpinBox
{
Q_OBJECT
public:
GammaSpinBox(QWidget * parent = 0, const char * name = 0 ) : QSpinBox(161, 400, 1, parent, name)
{
}
QString mapValueToText( int value )
{
return QString( "%1.%2" ) // 1.61 to 4.00
.arg( value / 100 ).arg( value % 100 );
}
int mapTextToValue( bool *ok )
{
return (int) ( 100 * text().toFloat() );
}
};
To copy to clipboard, switch view to plain text mode
When I try to build my app with one of these widgets placed in a dialog in designer I get the following error messages:
build
/linux
/gammaqt
/uic_setgammabase.
cc: In constructor `SetGammaBase
::SetGammaBase(QWidget*,
const char*,
bool, uint
)':build/linux/gammaqt/uic_setgammabase.cc:2459: error: invalid use of undefined type `struct GammaSpinBox'
....
build/linux/gammaqt/setgammabase.h:21: error: forward declaration of `struct GammaSpinBox'
build/linux/gammaqt/uic_setgammabase.cc: In constructor `SetGammaBase::SetGammaBase(QWidget*, const char*, bool, uint)':
build/linux/gammaqt/uic_setgammabase.cc:2459: error: invalid use of undefined type `struct GammaSpinBox'
....
build/linux/gammaqt/setgammabase.h:21: error: forward declaration of `struct GammaSpinBox'
To copy to clipboard, switch view to plain text mode
The ui file is setgammabase.ui and line 21 of setgammabase.h is:
class GammaSpinBox;
Line 2459 in uic_setgammabase.cc is:
GammaR = new GammaSpinBox( ButtonGroup4_2, "GammaR" );
It is probably something real basic that I am doing wrong but I can't see what it is. Any ideas?
Bookmarks