Results 1 to 8 of 8

Thread: Correct way to clear a form?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Correct way to clear a form?

    How would you clear a QPushButton?
    As buttons are probably the most often used elements in forms what would you expect if Qt would offer something like YourForm.clear() (assuming this would recursively go through all form elements and call their clear() method). Or if QWidget offered a pure virtual clear() method, that every derived class had to implement?

    A QLineEdit can be cleared. Sure. Also a QTextBox, QLabel any many more. But a QPushButton or a QSlider?
    Should these widget implement an empty clear() method? Just that their parent widget can call clear()?

    If you design a form your know all the elements in it, just because YOU designed it .
    I would implement something like this:
    Qt Code:
    1. YourForm::clear() {
    2. ui.lineEdit1->clear();
    3. ui.lineEdit2->clear();
    4. ui.plainTextEdit->clear();
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2007
    Location
    Austria (Europe)
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Correct way to clear a form?

    Quote Originally Posted by Boron View Post
    How would you clear a QPushButton?
    I never said something about a button and I'm pretty sure that you are familiar with the "if" command so you are able not to clear a button
    I only say class->inherits().

    Quote Originally Posted by Boron View Post
    If you design a form your know all the elements in it, just because YOU designed it .
    Are you kidding? Have you never worked in a team? Did you never design a class?

  3. #3
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Correct way to clear a form?

    What I wanted to say is that there cannot be a general way to clear a form that may contain any kind of widget, because there may be widget that cannot be cleared. I took a button as example for those widgets.

  4. #4
    Join Date
    Jun 2007
    Location
    Austria (Europe)
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Correct way to clear a form?

    The function in my self developed small Qt class library does exactly that by

    Qt Code:
    1. foreach(QLineEdit* widget, findChildren<qLineEdit*>())
    2. {
    3. if( !firsteditablewidget) firsteditablewidget = widget;
    4. modified = true;
    5. widget->clear();
    6. }
    7. foreach(ecTextEdit* widget, findChildren<ecTextEdit*>())
    8. {
    9. widget->clear();
    10. }
    11. foreach(QTableView* widget, findChildren<QTableView*>())
    12. {
    13. QAbstractItemModel * abstractmodel = widget->model();
    14. if( abstractmodel )
    15. {
    16. if( abstractmodel->inherits( "QSqlQueryModel"))
    17. {
    18. QSqlQueryModel *model = (QSqlQueryModel *)abstractmodel;
    19. model->clear();
    20. .....
    To copy to clipboard, switch view to plain text mode 

    All I wanted to know if there is a better way to achieve this...

Similar Threads

  1. How to get a reference for a control of the main form?
    By thiforums in forum Qt Programming
    Replies: 6
    Last Post: 20th March 2009, 17:20
  2. Replies: 1
    Last Post: 19th March 2009, 09:41
  3. Help me to load one form over another form PushButton
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 26th November 2008, 16:11
  4. visible main form?
    By triperzonak in forum Newbie
    Replies: 1
    Last Post: 12th June 2008, 09:00
  5. Calling a new form from current form
    By webgenius in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2007, 19:50

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
  •  
Qt is a trademark of The Qt Company.