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.
{
//Q_OBJECT
public:
//signals:
// void escapePress();
public:
printlineEdit
(QWidget *parent
= 0);
unsigned int ValuePut,val;
};
class printlineEdit : public QLineEdit
{
//Q_OBJECT
public:
//signals:
// void escapePress();
public:
printlineEdit(QWidget *parent = 0);
void keyPressEvent( QKeyEvent *event );
unsigned int ValuePut,val;
};
To copy to clipboard, switch view to plain text mode
its corresponding c++ file.
{
ValuePut=0;
//selectionStart ();
//setCursorPosition(0);
printf("Inside printline constr\n");
}
void printlineEdit
::keyPressEvent(QKeyEvent *event
) {
bool flag=0;
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;
}
}
}
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;
}
}
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks