Results 1 to 10 of 10

Thread: How to Open a New Dialog when a Row is Clicked..?

  1. #1
    Join Date
    Mar 2014
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12

    Post How to Open a New Dialog when a Row is Clicked..?

    Screenshot from 2014-04-03 20:51:24new.jpg

    Hello world!!

    i am in new in Qt not only Qt but i am new programing and i come over here to get an answer for my question that is:

    i am developing a program with a relationalship until now everything is ok -and- -by Qt- is easy to learn and understand becuase there are a lot of tutorials about everything.. so what i want to do now is.. when i click or select a row in my table then click a button another dialog should be opend and it should display only rows that have the same code in the column.. any idea please?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to Open a New Dialog when a Row is Clicked..?

    Connect your edit button clicked() signal to a slot. In the slot get the currentIndex() of the view, which tells you which row the table's current cell is in. (You could also use the view's selection if it allows only one row). You then use that to access the data from your model for your dialog.

  3. #3
    Join Date
    Mar 2014
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12

    Default Re: How to Open a New Dialog when a Row is Clicked..?

    Hello!

    Qt Code:
    1. connect(ui->editButton, SIGNAL(clicked()), this, SLOT(editDel()));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MyForm::editDel()
    2. {
    3. //code:
    4. }
    To copy to clipboard, switch view to plain text mode 

    my friend thanks for repling... as i said i am new to programing langouages can you please tell me what to do and explain the code.. thanx

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to Open a New Dialog when a Row is Clicked..?

    It depends quite a bit on what the dialog should do. Here is the sort of thing I meant:
    Qt Code:
    1. void MyForm::editDel()
    2. {
    3. const QModelIndex index = ui->tableView->currentIndex();
    4. if (index.isValid()) { // i.e. there is a current index
    5. MyDialog dialog(ui->tableView->model(), index.row(), this);
    6. dialog.exec();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    where I assumed a customised, single purpose dialog that takes a model and row at construction. That is, its constructor looks like:
    Qt Code:
    1. class MyDialog: public QDialog
    2. {
    3. Q_OBJECT
    4. public:
    5. MyDialog(QAbstractItemModel *model, int row, QWidget *p = 0);
    6. ...
    7. };
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to ChrisW67 for this useful post:

    jaafari (22nd April 2014)

  6. #5
    Join Date
    Mar 2014
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12

    Default Re: How to Open a New Dialog when a Row is Clicked..?

    Hello!

    i actually added the code to my forms but i do not know what should be changed.. so i got errors..

    please help thanks


    Added after 17 minutes:


    should i put all the code?
    Last edited by jaafari; 4th April 2014 at 20:44.

  7. #6
    Join Date
    Mar 2014
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12

    Default Re: How to Open a New Dialog when a Row is Clicked..?

    can anyone give me an exampl how to do that in both cpp files & h files ....please help

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to Open a New Dialog when a Row is Clicked..?

    You already have an example for launching a dialog. If you want to display the same model but filter the rows to show only those containing a certain value then you can use QSortFilterProxyModel on top of the main model.

  9. The following user says thank you to ChrisW67 for this useful post:

    jaafari (22nd April 2014)

  10. #8
    Join Date
    Mar 2014
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12

    Default Re: How to Open a New Dialog when a Row is Clicked..?

    My Code:


    cpp.file

    Qt Code:
    1. Deliveries::Deliveries(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Deliveries)
    4. {
    5.  
    6. ui->setupUi(this);
    7.  
    8. //-------------- connection settings-------------
    9. Login conn;
    10. if(!conn.connOpen())
    11. ui->label_deliveries_statut->setText("Failed to open the database");
    12. else
    13. ui->label_deliveries_statut->setText("Connected....");
    14. //-------------- connection settings-------------
    15.  
    16. deliveryModel = new QSqlRelationalTableModel(this);
    17. deliveryModel->setTable("deliveries");
    18. deliveryModel->select();
    19.  
    20. deliveryModel->setRelation(deliveryModel->fieldIndex("supplierid"), QSqlRelation("suppliers","id","name"));
    21. deliveryModel->setRelation(deliveryModel->fieldIndex("productid"), QSqlRelation("products","id","name"));
    22. deliveryModel->setRelation(deliveryModel->fieldIndex("tva"), QSqlRelation("tva","unity","type"));
    23. deliveryModel->setRelation(deliveryModel->fieldIndex("departmentid"), QSqlRelation("department","id","name"));
    24. deliveryModel->setRelation(deliveryModel->fieldIndex("deliverycodeid"), QSqlRelation("deliverycode","id","code"));
    25.  
    26. deliveryModel->setEditStrategy(QSqlRelationalTableModel::OnManualSubmit);
    27.  
    28.  
    29.  
    30. ui->deliveryView->setModel(deliveryModel);
    31.  
    32. ui->deliveryView->setItemDelegate(new QSqlRelationalDelegate(this));
    33. ui->deliveryView->setAlternatingRowColors(true);
    34. ui->deliveryView->setCornerButtonEnabled(true);
    35.  
    36. ui->deliveryView->setSelectionMode(QAbstractItemView::SingleSelection);
    37. ui->deliveryView->setSelectionBehavior(QAbstractItemView::SelectRows);
    38. ui->deliveryView->setSortingEnabled(true);
    39. ui->deliveryView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    40. ui->deliveryView->horizontalHeader()->setStretchLastSection(true);
    41. ui->deliveryView->resizeColumnsToContents();
    42. ui->deliveryView->setCurrentIndex(deliveryModel->index(0, 0));
    43.  
    44. ui->deliveryView->setColumnHidden(0/*Deliveries_Id*/, true);
    45.  
    46.  
    47. connect(ui->editButton, SIGNAL(clicked()), this, SLOT(editDel()));
    48.  
    49. }
    50.  
    51. Deliveries::~Deliveries()
    52. {
    53. delete ui;
    54. }
    55.  
    56. void Deliveries::editDel()
    57. {
    58. const QModelIndex index = ui->deliveryView->currentIndex();
    59. if (index.isValid()) { // i.e. there is a current index
    60. Dialog dialog(ui->deliveryView->deliveryModel(), index.row(), this);
    61. dialog.exec();
    62. }
    63. }
    To copy to clipboard, switch view to plain text mode 

    header.file
    Qt Code:
    1. namespace Ui {
    2. class Deliveries;
    3.  
    4. }
    5.  
    6. class Deliveries : public QDialog
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. explicit Deliveries(QWidget *parent = 0);
    12. ~Deliveries();
    13. private slots:
    14. void updateDel();
    15.  
    16. private:
    17. Ui::Deliveries *ui;
    18.  
    19.  
    20. QSqlRelationalTableModel *deliveryModel;
    21.  
    22. };
    23.  
    24. #endif // DELIVERIES_H
    To copy to clipboard, switch view to plain text mode 


    i do not know what next...

  11. #9
    Join Date
    Mar 2014
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12

    Default Re: How to Open a New Dialog when a Row is Clicked..?

    where should i use QSortFilterProxyModel in my dialog.cpp or in myForm.cpp ??

  12. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to Open a New Dialog when a Row is Clicked..?

    Assuming the Dialog displays everything in the model you pass it, you want to filter that before you give it to the Dialog constructor. Create a QSortFilterProxyModel, set its filter, and pas that to the Dialog.

  13. The following user says thank you to ChrisW67 for this useful post:

    jaafari (11th July 2015)

Similar Threads

  1. Replies: 3
    Last Post: 11th June 2012, 15:21
  2. To open new QML when pushButton is clicked
    By soumya in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 05:51
  3. How can i open a dialog when clicked on treewidget?
    By newermind in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2009, 11:13
  4. Replies: 10
    Last Post: 6th July 2008, 09:46
  5. Replies: 3
    Last Post: 13th May 2007, 20:55

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