PDA

View Full Version : Reading rows from qtableview and using them to draw in new window



thalorn
23rd November 2019, 18:09
Hello, I need little bit of help. I'm trying to draw a simple map of a grid based maze, but I got stuck at the start of my project. I loaded the data about the maze (coordinates of individual squares, position of the obstacles and orientation of a robot moving through the maze) from database to QTableView. From this tableview I would like to read values from individual rows and then by clicking on button draw in new window lines accordingly to the obstacles.
: would appreciate your help.

d_stranz
25th November 2019, 19:27
This sounds a lot like a homework problem to me. Aren't you supposed to be doing this on your own instead of asking for help here every time you run into a problem?

First, QTableView is simply a way to display and interact with your internal data structure. This data structure is usually wrapped by a QAbstractTableModel that the view uses for display. When you click on something in the table view, the view's QItemSelectionModel is filled in with the information about the selection. The QModelIndex items in this selection model tell you which entries were selected, and these indices point to your original table model's items.

It would be a very good idea for you to study the Qt Model / View tutorial (https://doc.qt.io/qt-5/modelview.html) and some of the many Qt model / view examples.