Results 1 to 5 of 5

Thread: Add a Qwidget dynamically

  1. #1
    Join Date
    Jun 2008
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Question Add a Qwidget dynamically

    Why this does not work ?

    Qt Code:
    1. void MyNotesMain::mousePressEvent(QMouseEvent *event)
    2. {
    3. mousePoint = event->globalPos();
    4.  
    5. QLineEdit *lineEdit = new QLineEdit(this);
    6. lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    7. lineEdit->setGeometry(QRect(mousePoint.x(), mousePoint.y(), 113, 20));
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    Nothing happens.

  2. #2
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Add a Qwidget dynamically

    You forget the

    Qt Code:
    1. ineEdit->show();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2008
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add a Qwidget dynamically

    Nothing happens.
    Qt Code:
    1. void MyNotesMain::mousePressEvent(QMouseEvent *event)
    2. {
    3. mousePoint = event->globalPos();
    4.  
    5. QLineEdit *lineEdit = new QLineEdit(this);
    6. lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    7. lineEdit->setGeometry(QRect(mousePoint.x(), mousePoint.y(), 113, 20));
    8. lineEdit->show();
    9. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Add a Qwidget dynamically

    Why don't you push QLineEdit *lineEdit to the header initialise it in the constructor. and then just call setGeometry in the mousePressEvent
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  5. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Add a Qwidget dynamically

    try to use
    mousePoint = event->pos();

    instead of

    mousePoint = event->globalPos();

Similar Threads

  1. Promoting the parent QWidget of a QWidget form
    By extrakun in forum Qt Tools
    Replies: 6
    Last Post: 16th April 2010, 14:19
  2. Adding a scrollbar to a QWidget
    By qtUser500 in forum Newbie
    Replies: 13
    Last Post: 2nd September 2009, 19:48
  3. Replies: 0
    Last Post: 11th November 2008, 15:36
  4. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  5. Error in put one QWidget in another QWidget
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 16:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.