[Interest] Setting current row in QSqlTableModel
M. Bashir Al-Noimi
mbnoimi at gmail.com
Thu Apr 18 18:53:56 CEST 2013
On Thu, Apr 18, 2013 at 6:43 PM, M. Bashir Al-Noimi <mbnoimi at gmail.com>wrote:
> Hi,
>
> Could you please guide me how can I set the current row in QSqlTableModel?
>
> PS
> I’ve QTableView and QComboBox both of them attached to same QSqlTableModel
> I want to set the current row in QTableView dependeing on selected index in
> QComboBox. I can get the selected index in QComboBox through
> currentIndexChanged(int index) slot but I don’t know to set the current in
> QSqlTableModel.
>
>
>
> 1. void MainWindow::on_comboBox_find_currentIndexChanged(int index)
> 2. {
> 3. if (p_db.isOpen()) {
> 4. //! \bug doesn't select the row although the index is
> correct!
> 5. if (p_tableModel->selectRow(index)) {
> 6. qDebug() << index;
> 7. }
> 8. }
> 9. }
>
> Voila I fixed it by:
1. void MainWindow::on_comboBox_find_currentIndexChanged(int index)
2. {
3. if (p_db.isOpen()) {
4. if (p_tableModel->selectRow(index)) {
5. ui->tableView_table->setCurrentIndex(p_tableModel->index(
index, 0));
6. qDebug() << index;
7. }
8. }
9. }
--
Best Regards
Muhammad Bashir Al-Noimi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130418/bf711aca/attachment.html>
More information about the Interest
mailing list