i
ironexmaidenAug. 25, 2017, 3:05 a.m.
QTableView connected with QSqlTableModel flickers (scrolls to the bottom and returns)
qt, qsql, QSqlDataBase, QSqlTableModel, QTableView
Hello guys I have a problem using table view. I have a
tableview connected with a QSqlTableModel. On its 2nd column I want to
have check state to control the row's Status (active/inactive) but when I
try to push the check box QTableView scrolls to the bottom and returns
to it's previous position. Is there any solution?
bool ProjectsModel::setData(const QModelIndex &index, const QVariant &value, int role) { if(index.column() == STATUS_INDEX) { QSqlRecord rec = this->record(index.row()); QString qrstr; qrstr = (rec.field(index.column()).value().toInt() == 1) ? "update " + tableName() + " set Status=0 where BRACE_ID=" : "update " + tableName() + " set Status=1 where BRACE_ID="; qrstr += QString().setNum(index.row()+1); braceDatabase->exec(qrstr.toUtf8().constData()); return true; } return false; } void DataBase::updateTablesSlot() { if(projectsModel) projectsModel->select(); if(attributesModel) attributesModel->select(); if(targetsModel) targetsModel->select(); } void DataBase::exec(const std::string &querystr) { QSqlQuery qr(db); qr.exec(querystr.c_str()); //qDebug() <<"Command :" << querystr.c_str() << "-> "<< query->lastError().text(); updateTables(); }

We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
Ua
- Unknown akadamn
- Jan. 24, 2025, 5:14 p.m.
Qt - Test 001. Signals and slots
- Result:84points,
- Rating points4
Ua
- Unknown akadamn
- Jan. 24, 2025, 4:22 p.m.
Qt - Test 001. Signals and slots
- Result:42points,
- Rating points-8
Last comments
ИМ
Django - Tutorial 017. Customize the login page to Django Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
Игорь МаксимовNov. 22, 2024, 9:51 p.m.

Evgenii LegotckoiOct. 31, 2024, 11:37 p.m.
Fb3 file reader on Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Django - Lesson 064. How to write a Python Markdown extension Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
Игорь МаксимовOct. 5, 2024, 4:51 p.m.
QML - Lesson 016. SQLite database and the working with it in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Now discuss on the forum
f
Рисование на QGraphicsScene при зажатой кнопке мыши Подскажите, пожалуйста! Как данный класс можно дополнить, чтобы созданные объекты можно было перемещать мышкой по сцене?
firstlunoxodFeb. 15, 2025, 1:46 p.m.

ДмитрийFeb. 3, 2025, 4:24 p.m.
не запускается компьютер!!! Не запускается компьютер (точнее работает блок , но сам монитор вообще жесть)В общем я ничего с интернета не скачивала в последнее время. На компе никаких левых пр…
Нужно запретить перемещение только некоторых итемов, остальные перемещать можно. Вопрос решен. Узнать QModelIndex элемента на который мы перетаскиваем другой элемент, можно с помощью функции indexAt(event->position().toPoint()) представления QTreeViev вызываемой в переопр…
OAuth2.0 через VK, получение email Спасибо большое за помощь и простите за то что отнял время своей невнимательностью.
Hello!
I think you need to use QItemDelegate for this (or same claas which was inherited from this class). Or You can use QTableWidget.
You can research article with checkboxes in QTableWidget .
May be it will be usefull for You.
And may be you need use for scroll method scrollTo()
Hello my friend and thank you for the help unfortunately I can't use QTableWidget for performance reasons, I must load big databases from csv files. If I try the second solution with the scroll It will have a disturbing effect the table will hop up and down every time the user presses the check state.
Christos,
Greeting from Thessaloniki, Greece
Ok. May be You need to use custom ItemDelegate for this.
And set delegate
Best Regards from Prague.
I changed my code to this one but the check state on click didn't change :(
I am not sure, but problem of this solution may be in Qt::Checked and Qt::Unchecked.
Because this enum has 3 states
That's the point I want the status of the row to be Active/Inactive PartiallyChecked option is useless for me. Do you refer that I had an error on this line ?
I am not sure, but may be you can try to check the following code in this row:
Hmm you may be right I will check it EVILEG and I will report later thank you