1 Attachment(s)
How to Open a New Dialog when a Row is Clicked..?
Attachment 10248
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?
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.
Re: How to Open a New Dialog when a Row is Clicked..?
Hello!
Code:
connect(ui->editButton, SIGNAL(clicked()), this, SLOT(editDel()));
Code:
void MyForm::editDel()
{
//code:
}
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
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:
Code:
void MyForm::editDel()
{
const QModelIndex index
= ui
->tableView
->currentIndex
();
if (index.isValid()) { // i.e. there is a current index
MyDialog dialog(ui->tableView->model(), index.row(), this);
dialog.exec();
}
}
where I assumed a customised, single purpose dialog that takes a model and row at construction. That is, its constructor looks like:
Code:
{
Q_OBJECT
public:
...
};
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?
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
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.
Re: How to Open a New Dialog when a Row is Clicked..?
My Code:
cpp.file
Code:
Deliveries
::Deliveries(QWidget *parent
) : ui(new Ui::Deliveries)
{
ui->setupUi(this);
//-------------- connection settings-------------
Login conn;
if(!conn.connOpen())
ui->label_deliveries_statut->setText("Failed to open the database");
else
ui->label_deliveries_statut->setText("Connected....");
//-------------- connection settings-------------
deliveryModel->setTable("deliveries");
deliveryModel->select();
deliveryModel
->setRelation
(deliveryModel
->fieldIndex
("supplierid"),
QSqlRelation("suppliers",
"id",
"name"));
deliveryModel
->setRelation
(deliveryModel
->fieldIndex
("productid"),
QSqlRelation("products",
"id",
"name"));
deliveryModel
->setRelation
(deliveryModel
->fieldIndex
("tva"),
QSqlRelation("tva",
"unity",
"type"));
deliveryModel
->setRelation
(deliveryModel
->fieldIndex
("departmentid"),
QSqlRelation("department",
"id",
"name"));
deliveryModel
->setRelation
(deliveryModel
->fieldIndex
("deliverycodeid"),
QSqlRelation("deliverycode",
"id",
"code"));
ui->deliveryView->setModel(deliveryModel);
ui->deliveryView->setAlternatingRowColors(true);
ui->deliveryView->setCornerButtonEnabled(true);
ui->deliveryView->setSortingEnabled(true);
ui->deliveryView->horizontalHeader()->setStretchLastSection(true);
ui->deliveryView->resizeColumnsToContents();
ui->deliveryView->setCurrentIndex(deliveryModel->index(0, 0));
ui->deliveryView->setColumnHidden(0/*Deliveries_Id*/, true);
connect(ui->editButton, SIGNAL(clicked()), this, SLOT(editDel()));
}
Deliveries::~Deliveries()
{
delete ui;
}
void Deliveries::editDel()
{
const QModelIndex index
= ui
->deliveryView
->currentIndex
();
if (index.isValid()) { // i.e. there is a current index
Dialog dialog(ui->deliveryView->deliveryModel(), index.row(), this);
dialog.exec();
}
}
header.file
Code:
namespace Ui {
class Deliveries;
}
{
Q_OBJECT
public:
explicit Deliveries
(QWidget *parent
= 0);
~Deliveries();
private slots:
void updateDel();
private:
Ui::Deliveries *ui;
};
#endif // DELIVERIES_H
i do not know what next...
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 ??
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.