PDA

View Full Version : Add a Qwidget dynamically



assismvla
1st September 2009, 23:16
Why this does not work ?



void MyNotesMain::mousePressEvent(QMouseEvent *event)
{
mousePoint = event->globalPos();

QLineEdit *lineEdit = new QLineEdit(this);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(mousePoint.x(), mousePoint.y(), 113, 20));

}


Nothing happens.

PaceyIV
2nd September 2009, 08:20
You forget the



ineEdit->show();

assismvla
3rd September 2009, 02:00
Nothing happens.


void MyNotesMain::mousePressEvent(QMouseEvent *event)
{
mousePoint = event->globalPos();

QLineEdit *lineEdit = new QLineEdit(this);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(mousePoint.x(), mousePoint.y(), 113, 20));
lineEdit->show();
}

ComaWhite
3rd September 2009, 02:32
Why don't you push QLineEdit *lineEdit to the header initialise it in the constructor. and then just call setGeometry in the mousePressEvent

nish
3rd September 2009, 06:14
try to use
mousePoint = event->pos();

instead of

mousePoint = event->globalPos();