Skip to content
  • 0 Votes
    4 Posts
    620 Views
    Z
    @VRonin yea, ty, already fix it
  • 0 Votes
    3 Posts
    651 Views
    A
    @Bonnie said in Trying to programatically fill a model for QTableView: Yes, the life cycle is definitely a problem. You should show the code when making the tabletModel a member of MainWindow. And there's no need to call show() when appending data. It turns out I was not initializing the table model in the constructor when making it a member. and you are correct the show() isn't needed. Now it all works. Thanks again!
  • 0 Votes
    4 Posts
    5k Views
    VRoninV
    You can use either QTreeWidget, QTableWidget, QTreeView+QStandardItemModel, QTableView+QStandardItemModel, QTreeView+QAbstactTableModel subclass, QTableView+QAbstactTableModel subclass for what you are trying to do. I would go with a QT*View+QStandardItemModel (tree or table doesn't matter). The functionalities you describe are: only some columns will be editable use QStandardItem::setFlag Entering a value in the cents column (a logarithmic measure of frequency) will change the value in the hertz column, and vice versa connect a slot to QStandardItemModel::dataChanged signal There will be a button next to the table to add an additional note to the scale connect a slot that calls QStandardItemModel::insertRows to the QPushButton::clicked signal
  • 0 Votes
    3 Posts
    2k Views
    VRoninV
    In 90% of the cases you can use QStandardItemModel instead of going through the minefield that is subclassing an abstract model. My advice is just to use that "universal model" instead of a custom one. If you really, really want to customise it as performance of QStandardItemModel is a problem then make sure you run your model through the Model Test (needs just a couple of trivial fixes to work on Qt5) that will tell you if you did everything as you were supposed to or you fell in the countless pitfalls of model subclassing
  • 0 Votes
    13 Posts
    6k Views
    S
    @raven-worx Jackpot! Thank you so much for your help!! Finally I did it using QFileSystemWatcher. Thumbs up for you (if possible?!). :) Thread marked as solved. Cheers
  • [SOLVED]QTableModel crashes on headerData

    Unsolved General and Desktop qabstracttablem model-view
    10
    1 Votes
    10 Posts
    4k Views
    mrjjM
    @RDiGuida Ok, so cnamMet would run out of scope and be deleted (when function ended) but sounds like data.rnames should have been working. Well if a copy on creation time works for you, its a wrap :)
  • Row selection

    General and Desktop qabstracttablem qt5.4 c++ qtableview row selection
    3
    0 Votes
    3 Posts
    2k Views
    S
    Hi, thanks for the reply. Yes, I set that flag to true but I can select a row by clicking indivual cell or horizontal header. I've overriden flags function in my model if I remove isSelectable flag i can't select anything. Qt::ItemFlags TableModel::flags(const QModelIndex &index) const { if(!index.isValid()) { return Qt::ItemIsEnabled; } if(index.column() == 1) { if(modelList.at(index.row()).isArray) { return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEditable; } return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; } return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable; }
  • 0 Votes
    3 Posts
    2k Views
    R
    Hi @zeryx I've tried your code with the change below and it works fine (columns are getting populated at runtime) use var headerData = baseTableModel.headerList instead of var headerData = headers at line number 11 in schedulerViewingPane.qml (http://hastebin.com/genuhisodu.sm). Since you are already passing EmployeeModelTable instance baseTableModel to the qml then why not use the headerList property from the instance instead of setting it again.
  • 0 Votes
    7 Posts
    7k Views
    SGaistS
    Qt provides Q_DECL_OVERRIDE which extends to the override keyword if C++11 is used and to nothing otherwise