Ratheendrans
3rd April 2011, 08:30
Dear All,
I made a subclass of QLineEdit class and implemented its constructor and keyPressEvent event handler,then I promoted one of the instances of QLineEdit to subclass with QT Designer by right clicking and selecting the promote option. I am able to call keyPressEvent() method in my application. however the constructor of this subclass is never called.
header file.
class printlineEdit : public QLineEdit
{
//Q_OBJECT
public:
//signals:
// void escapePress();
public:
printlineEdit(QWidget *parent = 0);
void keyPressEvent( QKeyEvent *event );
unsigned int ValuePut,val;
};
its corresponding c++ file.
printlineEdit::printlineEdit(QWidget *parent):QLineEdit(parent)
{
ValuePut=0;
//selectionStart ();
//setCursorPosition(0);
printf("Inside printline constr\n");
}
void printlineEdit::keyPressEvent(QKeyEvent *event)
{
bool flag=0;
QString ch("");
switch(event->key())
{
case Qt::Key_Left:
break;
case Qt::Key_Right:
break;
case Qt::Key_Up:
break;
case Qt::Key_Down:
break;
case Qt::Key_Return:
flag=1;
printf("Enter Pressed\n");
break;
}
}
}
Now for the above code the constructor printlineEdit(QWidget *parent) is never called.
Kindly tell me how to implement a constructor in these scenario.
Ratheendran
I made a subclass of QLineEdit class and implemented its constructor and keyPressEvent event handler,then I promoted one of the instances of QLineEdit to subclass with QT Designer by right clicking and selecting the promote option. I am able to call keyPressEvent() method in my application. however the constructor of this subclass is never called.
header file.
class printlineEdit : public QLineEdit
{
//Q_OBJECT
public:
//signals:
// void escapePress();
public:
printlineEdit(QWidget *parent = 0);
void keyPressEvent( QKeyEvent *event );
unsigned int ValuePut,val;
};
its corresponding c++ file.
printlineEdit::printlineEdit(QWidget *parent):QLineEdit(parent)
{
ValuePut=0;
//selectionStart ();
//setCursorPosition(0);
printf("Inside printline constr\n");
}
void printlineEdit::keyPressEvent(QKeyEvent *event)
{
bool flag=0;
QString ch("");
switch(event->key())
{
case Qt::Key_Left:
break;
case Qt::Key_Right:
break;
case Qt::Key_Up:
break;
case Qt::Key_Down:
break;
case Qt::Key_Return:
flag=1;
printf("Enter Pressed\n");
break;
}
}
}
Now for the above code the constructor printlineEdit(QWidget *parent) is never called.
Kindly tell me how to implement a constructor in these scenario.
Ratheendran