Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. model-view
    Log in to post

    • UNSOLVED How to change QTableView data based on selection in QComboBox.
      General and Desktop • qcombobox model-view qtableview c++ qitemselection selection model • • jaivardhanf  

      4
      0
      Votes
      4
      Posts
      83
      Views

      @jaivardhanf said in How to change QTableView data based on selection in QComboBox.: So below is my code. Something seems to have gone wrong with the code tags, making it hard to read and potentially missing code. Qt::ItemFlags LineModel::flags(const QModelIndex& index) const { return Qt::ItemIsEditable | QAbstractTableModel::flags(index); } Adding the ItemIsEditable flag doesn't matter if the goal isn't to edit the item through the view. This is how I connect the signal and slot connect(ui->lineClass, &QComboBox::currentTextChanged, this, &GetOptionsClass::TextChanged); Verify that the slot is called when it should be, and that the arguments are as expected.
    • UNSOLVED Sync selectionModel between two views where one view has a transposed Model of the other
      General and Desktop • model-view beginner selectionmodel • • firen  

      9
      0
      Votes
      9
      Posts
      331
      Views

      @firen said in Sync selectionModel between two views where one view has a transposed Model of the other: That seems ok for my needs Try inserting/removing rows/columns or sorting and you'll see it will break
    • SOLVED model view: How to tied up data form view with underlying data
      General and Desktop • model-view custom type mapping • • AlexandruToma  

      5
      0
      Votes
      5
      Posts
      307
      Views

      @AlexandruToma No, you will impose sorting via a QSortFilterProxyModel on top of your model if sorting is wanted. View will access that. Your indexes here will be unaffected. That is why a proxy model is nice :)
    • UNSOLVED Custom model of nested lists to QML
      General and Desktop • qml model-view qabstractitemmo qabstractlistmo • • EStudley  

      2
      0
      Votes
      2
      Posts
      159
      Views

      Still not sure what's the best design here.
    • UNSOLVED Unable to edit QSqlTableModel from QML
      QML and Qt Quick • model sqlite model-view qsqltablemodel • • daljit97  

      4
      0
      Votes
      4
      Posts
      287
      Views

      @daljit97 said in Unable to edit QSqlTableModel from QML: , Qt::EditRole); Then you should probably pass the role and not editRole, otherwise model won't know which column to update.
    • UNSOLVED Making a VST Effect Stack using Model/View
      General and Desktop • model-view listwidget vst • • rtavakko  

      5
      0
      Votes
      5
      Posts
      336
      Views

      @SGaist Thanks, I will dig into it more
    • UNSOLVED Disable Qt::CheckStateRole
      General and Desktop • model-view • • ochampao  

      4
      0
      Votes
      4
      Posts
      1458
      Views

      You can use a QIdentityProxyModel
    • UNSOLVED Inconsistency between model and view while updating QSqlTableModel cell
      QML and Qt Quick • qml model-view modelview model view prog • • Ahti  

      9
      0
      Votes
      9
      Posts
      495
      Views

      Did you saw the third argument of the signal ? The one you are currently not using in the code you provided. It's the one containing the custom roles.
    • UNSOLVED How to edit a cell in a model inheriting from QSqlTableModel
      QML and Qt Quick • qml model-view • • Ahti  

      7
      0
      Votes
      7
      Posts
      435
      Views

      @SGaist @Christian-Ehrlicher How would I let the view know about the data change ? And I would like to mention I am displaying the list of users with UserRole like this: QVariant UserModel::data(const QModelIndex &index, int role) const{ QVariant value; if (index.isValid()) { if (role < Qt::UserRole) value = QSqlQueryModel::data(index, role); else { int columnIdx = role - Qt::UserRole - 1; QModelIndex modelIndex = this->index(index.row(), columnIdx); value = QSqlQueryModel::data(modelIndex, Qt::DisplayRole); } } return value; } QHash<int, QByteArray> UserModel::roleNames() const{ QHash<int, QByteArray> roles; for (int i = 0; i < record().count(); i ++) { roles.insert(Qt::UserRole + i + 1, record().fieldName(i).toUtf8()); } return roles; }
    • UNSOLVED How to edit cell row in costume model which inherits from QSqlTableModel ?
      QML and Qt Quick • qml model-view qsqltablemodel • • Ahti  

      2
      0
      Votes
      2
      Posts
      168
      Views

      @Ahti Dunno, but why don't you start by showing us/yourself the return values of the calls to user_model.setData(user_model.index(...? What's the result for you of: https://doc.qt.io/qt-5/qsqltablemodel.html#editStrategy ?
    • UNSOLVED Accessing and altering the same view from different Qml files
      QML and Qt Quick • qml model-view model view prog • • Ahti  

      2
      0
      Votes
      2
      Posts
      465
      Views

      You can get StackView instance from Profile.qml quite easy, using StackView attached properties. Define new property at your StackView: StackView { id: home property var modeldata: null // Define StackView property initialItem: Pane { ... ListView { ... delegate: SwipeDelegate { ... swipe.onCompleted: { if (swipe.position > 0) { home.modeldata = model; // Set StackView property home.pop(); home.push("Profile.qml"); } ... } ... } } } } And then at Profile.qml you can easily get attached StackView property: Pane { id: profile ... Button { ... text: "Delete" onClicked: { let modeldata = profile.StackView.view.modeldata; // Accessing StackView property via attached properties if (modeldata !== null) { user_model.removeRow(modledata.index); } ... } } } In this case you do not need workaround with helper row. Also if you need some objects like your helper - better way is to use QtObject rather than visual 'invisible' object.
    • UNSOLVED Inconsistency between model and view after removing a row from a table
      QML and Qt Quick • qml model-view model view prog • • Ahti  

      2
      0
      Votes
      2
      Posts
      182
      Views

      @Ahti said in Inconsistency between model and view after removing a row from a table: JsonObject u_data; u_data.insert("id", model->record(index.row()).value(0).toInt()); u_data.insert("name", model->record(index.row()).value(1).toString()); if (role == Qt::DisplayRole) return u_data; That's inefficient. If you only support DisplayRole, then you can move that QJsonObject directly into that if statement. if (role == Qt::DisplayRole) { QJsonObject u_data; u_data.insert("id", model->record(index.row()).value(0).toInt()); u_data.insert("name", model->record(index.row()).value(1).toString()); return u_data; } Second, you should use the parent here, even if it is a flat list: beginRemoveRows(QModelIndex(), first, last); response = model->removeRow(first, QModelIndex()); beginRemoveRows(parent, first, last); response = model->removeRow(first, parent); But why you get this strange behavior when removing - I don't know. Perhaps it has something to do with the fact that you have two models here - UseModel is a list model and your model variable is a QSqlTableModel (which inherits from the same base class as list model). Perhaps these calls get duplicated, although it is unlikely. Try adding some qDebug() calls into removeRows(), or run it through a debugger, to see what is happening.
    • SOLVED What to subclass?
      General and Desktop • model-view qsqlquerymodel subclassing editable model • • Pl45m4  

      9
      0
      Votes
      9
      Posts
      613
      Views

      @christian-ehrlicher said in What to subclass?: Especially compared to the idea to parse the data somehow from a sqlite file Where I have said that? :) I never had the idea to "parse" the sqlite file directly. I will try to get the data with a query first and see what I can do with it :) (I guess QSqlResult is the key?!)
    • UNSOLVED Using QAbstractItemModel in Models that haven't any list.
      QML and Qt Quick • qml model-view qabstractmodel • • overlord  

      12
      0
      Votes
      12
      Posts
      529
      Views

      @overlord said in Using QAbstractItemModel in Models that haven't any list.: I am invastigating proper way to use model/view pattern. The model/view pattern in Qt is designed for cases where you have an arbitrary number of rows of data. Your sensors don't quite match this use-case. Therefore, the model/view pattern is not suitable for your sensors. I suggest you choose the right tool for the job: Just use a data structure for your sensors, like @SGaist suggested. If you want to investigate how to use the model/view pattern, try implementing a model with rows. For example, an address book.
    • UNSOLVED Using Qt's Model/View pattern on custom UIs
      QML and Qt Quick • model-view • • overlord  

      3
      0
      Votes
      3
      Posts
      288
      Views

      I will show one datasets at the same time. This data periodically updated. So I haven't any list.
    • UNSOLVED Need help from QT Experts ( Model / View for QDateTimeEdit widget)
      General and Desktop • model-view qdatetimeedit qdatawidgetmapp • • chakry  

      27
      0
      Votes
      27
      Posts
      1745
      Views

      Can you reformat the answer? it's difficult to follow...
    • SOLVED Showing data from multiple SQLite tables
      General and Desktop • database model-view sqlite view • • Pl45m4  

      7
      0
      Votes
      7
      Posts
      1262
      Views

      @Christian-Ehrlicher Hm ok... That's not what I wanted to hear :D Thank you anyway. I think, I will subclass QSqlQueryModel then and write functions to make the model writable...
    • SOLVED UI Responsiveness and QListView updating during load of large data into model
      General and Desktop • model-view responsive • • bepaald  

      10
      0
      Votes
      10
      Posts
      2237
      Views

      Boiler plate code which you are trying to implement is already taken care by Qt using Signals/Slots across threads. It is better to use tried & tested inbuilt mechanism. It is good with code maintainability & readability as well. Suggest to use signals/slots.
    • UNSOLVED How to add tooltip to Tableview from C++ model
      General and Desktop • qml model-view tooltip • • milan  

      16
      0
      Votes
      16
      Posts
      3111
      Views

      @milan Hi, You can do it using a delegate and a ToolTip component: import QtQuick.Controls 2.2 as QC2 ... TableViewColumn { id: titleColumn title: "Title" role: "title" movable: false resizable: false width: tableView.viewport.width - authorColumn.width delegate: QC2.ItemDelegate{ id: lb hoverEnabled: true text: model.title width: parent.width QC2.ToolTip { delay: 250 parent: lb visible: lb.hovered text: "Tooltip text" //put styleData.tooltip here } } } This code is extracted from the TableView example which I have modified to add the ToolTip.
    • UNSOLVED Tree View with varying column counts
      General and Desktop • qtreeview model model-view treemodel • • DaveK 0  

      1
      0
      Votes
      1
      Posts
      612
      Views

      No one has replied

    • UNSOLVED What layout to use for data listing if I don't need most of the model features?
      General and Desktop • model-view table model • • lansing  

      3
      0
      Votes
      3
      Posts
      543
      Views

      @mrjj Thanks I got it to work. ui->setupUi(this); ui->tableWidget->setColumnCount(2); ui->tableWidget->setRowCount(numberSet.size()); ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); QStringList tableHeader = {"Number", "Result"}; ui->tableWidget->setHorizontalHeaderLabels(tableHeader); int rowCounter = 0; for(int i : numberSet) { ui->tableWidget->setItem(rowCounter, 0, new QTableWidgetItem(QString::number(i))); ui->tableWidget->setItem(rowCounter, 1, new QTableWidgetItem(someConversion(i))); rowCounter++; }
    • SOLVED Replicate the contents of the current selected item in QTableView
      General and Desktop • qtableview signal & slot model-view view • • Arthur Araruna  

      7
      0
      Votes
      7
      Posts
      1210
      Views

      @Arthur-Araruna said in Replicate the contents of the current selected item in QTableView: both column and row indices All you need to do is replace currentRowChanged with currentIndexChanged
    • SOLVED Custom Widget in QListView/QTreeView expands whole width
      General and Desktop • model-view custom widget modelview • • SKovalev  

      4
      0
      Votes
      4
      Posts
      1303
      Views

      Finaly I have finished my little example! Previous version have been really buggy in items move. So I have to subclass from QAbstractItemModel. Many thanks to @Patou355 with his solution. NB I haven't deal with mousePressEvent() yet.
    • SOLVED Implementing chat type listview with text bubbles
      General and Desktop • model-view qlistview custom item chatting textsize • • bepaald  

      10
      0
      Votes
      10
      Posts
      3598
      Views

      @SGaist thank you, it has worked a treat! I appreciate your help. Steve Q.
    • SOLVED Dynamically change a component
      QML and Qt Quick • model-view load dynamic qml • • MoaMoaK  

      5
      0
      Votes
      5
      Posts
      2634
      Views

      Ok, nice, these three answers (StackView / StackLayout / Loader + Component) were what I was looking for. I tried each one and I think I'll stick with the StackView and the replace method as it's easy to have a fading transition with it. And I've already found a use to improve my code for the Loader so I also thank you for that. Thx for the help.
    • UNSOLVED Implementing Drag and Drop with QTreeView
      General and Desktop • model-view drag and drop treeview itemmodel • • jonasqt  

      1
      0
      Votes
      1
      Posts
      2552
      Views

      No one has replied

    • SOLVED One or Multiple QtTreeModel(s) in different Tabs?
      General and Desktop • model-view mvc tabs treemodel • • Opa114  

      13
      0
      Votes
      13
      Posts
      3328
      Views

      thanks. i will try it :)
    • SOLVED How to retrieve items indices from a treeView?
      QML and Qt Quick • qml model-view treeview index delegates • • Haitham  

      11
      0
      Votes
      11
      Posts
      5872
      Views

      @VRonin Can you please provide an example or something to follow? Because I am still a newbie at both Qt and QML. Sorry for bothering you with my many questions. Update: as you can see in the code, I change the state of the delegate through the mouse area in the delegate (it's commented out in the code). I was using it to test the states, now I've noticed another thing; Whenever I collapse the parent Item and then expand it, the previous states are not saved....does this have to do anything with what you mentioned?
    • UNSOLVED QAbstractTableModel hard to set up
      General and Desktop • qtableview qtablewidget model-view qabstracttablem qtablewidgetite • • moffa13  

      3
      0
      Votes
      3
      Posts
      1171
      Views

      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
    • UNSOLVED QML TreeView - how to apply delegate to certain items in the tree?
      QML and Qt Quick • qml model-view delegate treeview • • Haitham  

      9
      0
      Votes
      9
      Posts
      7969
      Views

      @6thC did your application consist of a tree and you could apply a delegate to specific items? because that's where I'm stuck now. I am still researching on how to connect QML with C++ and as usual if I figured out a way of applying delegates to specific items based on a logical condition (like your warning and maximum states), I will let you know. Thanks for your time bro!
    • SOLVED change QSortFilterProxyModel behaviour for multiple column filtering
      General and Desktop • qtableview model-view qsortfilterprox qstandarditemmo filtering • • IMAN4K  

      9
      0
      Votes
      9
      Posts
      7320
      Views

      @IMAN4K said in change QSortFilterProxyModel behaviour for multiple column filtering: Answer from stackfverflow : http://stackoverflow.com/questions/39488901/change-qsortfilterproxymodel-behaviour-for-multiple-column-filtering This answer is the typical example that lead people to say subclassing QSortFilterProxyModel, which would likely have a very limited reusability It's bad. the proxy model implementation should not depend on the structure of the underlying data in sourceModel
    • UNSOLVED How to disable filtering option for a QTreeView or Model?
      General and Desktop • qtreeview model-view • • NIXIN  

      4
      0
      Votes
      4
      Posts
      1636
      Views

      @NIXIN class MySortFilterProxyModel : public QSortFilterProxyModel { Q_OBJECT Q_PROPERTY(bool FilterEnabled READ isFilterEnabled WRITE setFilterEnabled ) public: virtual bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const { if( !m_IsFilterEnabled ) return true; // your filtering code here } bool isFilterEnabled() const { return m_IsFilterEnabled }; void setFilterEnabled( bool enabled ) { if( m_IsFilterEnabled != enabled ) { m_IsFilterEnabled = enabled; this->invalidate(); } } private: bool m_IsFilterEnabled;
    • SOLVED QAbstractListModel as property
      General and Desktop • qml c++ model-view qt5.7 qabstractlistmo • • romsharkov  

      3
      0
      Votes
      3
      Posts
      3816
      Views

      @SGaist returning a pointer in the getter and defining the Q_PROPERTY as a pointer to the list worked out fine! Thanks for that!
    • UNSOLVED Updating a proxy model
      General and Desktop • model-view • • KlimichKartorGnusov  

      8
      0
      Votes
      8
      Posts
      2689
      Views

      Like I said, without seeing any code I can't comment on whether the wrong index is being used or something else is going on.
    • SOLVED Transforming and filtering a model
      General and Desktop • model-view • • KlimichKartorGnusov  

      6
      0
      Votes
      6
      Posts
      1746
      Views

      You don't need all of this. Just use the top-most index. Modifying its content will propagate it back to the bottom index.
    • UNSOLVED Set minimum column width to QTableView.
      General and Desktop • qtableview model-view mvc qheaderview • • tokafr  

      5
      0
      Votes
      5
      Posts
      19687
      Views

      Hi, You can try with the QHeaderView::minimumSectionSize property
    • UNSOLVED One delegate for 2 model object.
      General and Desktop • model-view modelview model view prog delegates • • tokafr  

      2
      0
      Votes
      2
      Posts
      964
      Views

      @tokafr said: Mydelegate *delegate = new Mydelegate; hi, i might miss something but why dont you just create another instance? Mydelegate *delegate2= new Mydelegate; view2 -> setItemDelegate(delegate2); Normally a delegate (instance) is not shared between views as its not intended.
    • UNSOLVED How to style QTreeView items by role with CSS ?
      General and Desktop • qtreeview model-view css qtwidgets styles • • Zylann  

      9
      0
      Votes
      9
      Posts
      8326
      Views

      I finally managed to get custom colors. I gave my QTreeView an object name to be able to write this in CSS: m_treeView->setObjectName("MyTreeView"); m_treeView->setStyleSheet("QTreeView#MyTreeView::item {color: none;}"); basically now my model controls text color through Qt::ForegroundRole regardless of the application's CSS. I feel like it's the wrong place to put theming, but it works for me at the moment. Well... until we decide to have different themes :-°
    • UNSOLVED [SOLVED]QTableModel crashes on headerData
      General and Desktop • model-view qabstracttablem • • RDiGuida  

      10
      1
      Votes
      10
      Posts
      3099
      Views

      @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 :)