Results 1 to 4 of 4

Thread: Updating a QTableWidget through a Dialog

  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Updating a QTableWidget through a Dialog

    Hello anyone

    I have a question
    I want to update a QTableWidget through a Dialog is this possible?
    When i click with the mouse on a item in the QTableWidget it popup a Dialog.
    When i compile everthing works fine but i don't see any item displaying in my Dialog.
    I have tried severall options.
    See code

    Qt Code:
    1. void ContactWindow::edit(QTableWidgetItem *item )
    2. {
    3. if(item != contactTable->currentItem())
    4. return;
    5.  
    6. if(item)
    7. {
    8. contactDialog dlg(this);
    9. if(dlg.exec() == QDialog::Accepted)
    10. dlg.leBedrijf->setText(item->text());
    11. }
    12.  
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Moscow, Russia
    Posts
    20
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Updating a QTableWidget through a Dialog

    1: contactDialog dlg(this);
    2: if(dlg.exec() == QDialog::Accepted)
    3: dlg.leBedrijf->setText(item->text());
    You try to set some dialog properties in the string 3 (see quoted text) after the dialog is executed and closed (string 2) because the dialog is modal. Try the following:

    Qt Code:
    1. ContactDialog dlg(this);
    2. dlg.setSomeField(item->text());
    3. if (dlg.exec() == QDialog::Accepted) {
    4. // Do something
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Updating a QTableWidget through a Dialog

    Thanks vitaly for your answer.
    The problem is solved.

  4. #4
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Thanks
    3
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating a QTableWidget through a Dialog

    Quote Originally Posted by dragon
    Hello anyone

    I have a question
    I want to update a QTableWidget through a Dialog is this possible?
    When i click with the mouse on a item in the QTableWidget it popup a Dialog.
    When i compile everthing works fine but i don't see any item displaying in my Dialog.
    I have tried severall options.
    See code
    In addition to Vitaly's answer, you could also preset values in controls in the class of the dialog:
    Qt Code:
    1. #ifndef DLGLOGIN_H
    2. #define DLGLOGIN_H
    3. #include "ui_dlglogin.h"
    4.  
    5. class dlgLogin : public QDialog
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. Ui::dlgLoginUi dui;
    11. dlgLogin()
    12. {
    13. // called with 'dlgLogin dlg'. Only ID and password required
    14. dui.setupUi(this);
    15. dui.leUserName->setText("your revid");
    16. dui.leUserPassword->setText("");
    17. dui.leUserName->setFocus();
    18. dui.leUserName->selectAll();
    19. }
    20. };
    To copy to clipboard, switch view to plain text mode 
    then retrieve them like this:
    Qt Code:
    1. //main.cpp
    2. #include <QApplication>
    3. #include <QSqlDatabase>
    4. #include <QSqlError>
    5. #include <QMessageBox>
    6.  
    7. #include "homestead.h"
    8. #include "dlglogin.h"
    9. #include "wholenamedlg.h"
    10. #ifdef _WIN32 // on Windows
    11. #define DBDRIVER "QOCI"
    12. #define DBHOST "orc1"
    13. #define DBNAME "orc1"
    14. #else // must be on Linux
    15. #define DBDRIVER "QPSQL"
    16. #define DBHOST "localhost"
    17. #define DBNAME "homestead"
    18. #endif
    19.  
    20. int main( int argc, char * argv[] ) {
    21. QString strRejected = "";
    22. QApplication app(argc, argv);
    23. app.setQuitOnLastWindowClosed(false);
    24. dlgLogin dlg;
    25. if( dlg.exec() == QDialog::Accepted ){
    26. QSqlDatabase hapdb = QSqlDatabase::addDatabase(DBDRIVER);
    27. hapdb.setHostName(DBHOST);
    28. hapdb.setDatabaseName(DBNAME);
    29. hapdb.setUserName(dlg.dui.leUserName->text());
    30. hapdb.setPassword(dlg.dui.leUserPassword->text());
    31. if ( hapdb.open() ) {
    32. homestead ht;
    33. ht.RevID = dlg.dui.leUserName->text();
    34. ht.show();
    35. app.setQuitOnLastWindowClosed(true);
    36. return app.exec();
    37. } else {
    38. strRejected = QString("The Login was rejected because: %1").arg(hapdb.lastError().text()).toLatin1();
    39. QMessageBox::information(0,"Login Rejected!",strRejected,
    40. QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
    41. return 1;
    42. }
    43. } else {
    44. strRejected = QString("User Canceled the login!").toLatin1();
    45. QMessageBox::information(0,"Login Rejected!",strRejected,
    46. QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
    47. return 2;
    48. }
    49. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Issue with Modelless dialog on Mac
    By Satyanarayana Chebrolu in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2009, 10:10
  2. Replies: 9
    Last Post: 13th August 2008, 18:07
  3. QGraphicsView: Dialog Position Doubt
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2007, 17:48
  4. Problems updating a dialog
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 1st April 2006, 10:17
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

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.