Skip to content
  • 0 Votes
    5 Posts
    192 Views
    Pl45m4P

    @Pl45m4 said in How to add a row to a subclass of QAbstractTableModel?:

    For more detail check out the Editable TreeView Example
    (it's TreeView but in general the insert/remove procedure of rows and cols is the same)

    https://doc.qt.io/qt-6/qtwidgets-itemviews-editabletreemodel-example.html

    @jdent see here

  • 0 Votes
    34 Posts
    2k Views
    J

    Finally: I removed the call to a new QHeaderView and the header now works! -- it responds to mouse clicks!!
    Thank you!!

  • 0 Votes
    10 Posts
    866 Views
    JonBJ

    @jdent
    Are you asking about void QDataWidgetMapper::setCurrentModelIndex(const QModelIndex &index)

    Sets the current index to the row of the index if the orientation is horizontal (the default), otherwise to the column of the index.
    This convenience slot can be connected to the signal currentRowChanged()

    connect(myTableView->selectionModel(), &QItemSelectionModel::currentRowChanged, mapper, &QDataWidgetMapper::setCurrentModelIndex);
  • 0 Votes
    7 Posts
    488 Views
    JonBJ

    @jdent said in How do I make a QTableView readonly?:

    @Christian-Ehrlicher sorry did not find any info on ItemFlags for QTableView

    In Qt's model-view paradigm the flags are returned by the model: Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex &index) const, values flags Qt::ItemFlags. Qt::ItemIsEditable determines whether the model tells the view items are editable or not. A view like QTableView will call this, behind the scenes without you doing anything, and make its interface correspond to what the model wants. @mpergand's implementation does not return Qt::ItemIsEditable so items won't be editable. QTreeView will show items as non-editable.

  • 0 Votes
    3 Posts
    382 Views
    L

    @SGaist said in Table view resize ability with mouse events:

    e resized like any other widge

    I created a model class and used it in qml as TableView.

    My goal is to create a view that will be populated with tables, and the tables should be movable and resizable.

    So I started with one table, then I realized that there is no event for table resizing using the mouse.

  • 0 Votes
    5 Posts
    453 Views
    J

    @JonB I'm still wondering if the right approach would be to use a QItemViewDelegate subclass. I need custom painting of the rows when they come into view based on a global UI setting (colored or normal display) and the content of one of the cells in the row (the threadID).

    The Star Delegate example seems to indicate that custom cell painting is done via these view delegates.

    I thought that the way these delegates are supposed to work is that they get called for painting or editing on demand (i.e. when their cells are visible via the scrollbars or double clicked for editing).

    This way the change from normal to colored rows would refresh the visible view (I don't really need to store the background with each item in the table as it is just for visibility purposes.

  • 0 Votes
    8 Posts
    689 Views
    JonBJ

    @FumbleFingers said in Find and highlight a specific row in tableview:

    It may not be everyone's favourite coding style, but it works for me.

    Umm, you assign to idx in the middle of passing a parameter, and then use it afterwards!? :)

  • 0 Votes
    7 Posts
    1k Views
    R

    @jsulm said in QTableView clicked() not triggering when dragging and selecting a range of data in the table?:

    @R-P-H Mouse click means that mouse button was pressed AND released over same widget. Pressing mouse button down over one widget and releasing it over another isn't a click.
    You can use https://doc.qt.io/qt-6/qabstractitemview.html#pressed

    pressed() worked for me. Thanks !

  • 0 Votes
    2 Posts
    792 Views
    J.HilkJ

    @vinaygopal
    according to the documentation:

    https://doc.qt.io/qt-5/qml-qtquick-controls-tableviewcolumn.html#delegate-prop

    this should do the trick:

    Component{ id:firstColumnComponent Item { id: toplevelItem property bool textpresent: true Row{ spacing: 10 TextField{ id:te width: 100 text: styleData.value maximumLength: 20 onAccepted:{ console.log("the editing is finished to",te.text) peopleTable.editfinished(te.text,styleData.value) } } Image { id: fav_image source: "qrc:/favourite_icon.png" height: 20 width: 40 MouseArea{ anchors.fill: parent onClicked: { console.log("the current index is",styleData.row) //Change happened here } } } } } }
  • 0 Votes
    3 Posts
    500 Views
    V

    @fcarney

    Got it thank you so much :)

  • 0 Votes
    10 Posts
    2k Views
    jeanmilostJ

    Thanks to all for the replies.

    I finally resolved the issue by replacing the TableView by a ListView and rewriting the columns handling manually. As the ListView draws the whole item content once, all the above mentioned issues are resolved at the same time.

    However very interesting concepts were presented here, and they may help me for other similar situations in the future. Once again, thank you very much to took the time to help me and reply to my questions.

  • 0 Votes
    6 Posts
    2k Views
    VRoninV

    QHeaderView does not use delegates unfortunately. The solution I'd suggest is to have a QLineEdit widget spawn on top of the header to do the editing rather than spawning a dialog