Skip to content
  • 0 Votes
    1 Posts
    51 Views
    No one has replied
  • 0 Votes
    1 Posts
    204 Views
    No one has replied
  • 0 Votes
    11 Posts
    692 Views
    Pl45m4P

    @Donald9307

    Just to clear the confusion, do you have any model or in which way do you use your query?
    Because there is no QSqlQuery::setQuery() (as in the title).

    But good to hear that it worked for you :)

  • 0 Votes
    3 Posts
    365 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
    2 Posts
    231 Views
    Christian EhrlicherC

    I think it's a style issue as explained here: https://doc.qt.io/qt-6/stylesheet.html
    "For example, it might be tempting to set the QPalette::Button role to red for a QPushButton to obtain a red push button. However, this wasn't guaranteed to work for all styles, because style authors are restricted by the different platforms' guidelines and (on Windows and macOS) by the native theme engine."

    Which OS & Qt style do you use?

  • 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
    6 Posts
    420 Views
    J

    @JonB ok. I'm picking up what you're laying down. I went through my code and made sure my structure is actually following the patterns I've decided on. To answer your question, I do need access to both the proxy model and source model, but thanks for clarifying the distinction. Thank you for your time!

  • 0 Votes
    2 Posts
    264 Views
    Axel SpoerlA

    Could you share a minimal example please?

  • 0 Votes
    3 Posts
    483 Views
    artwawA

    @SGaist You are, as usual, right and I am the absolute moron :D

    I forgot to take into the account starting point of the cell in paint... Too much time has passed since I had to write the delegate it seems.
    The solution of the problem was correcting the drawPixamp starting point (add opt.rec.x() and opt.rect.y() respectively):

    painter-drawPixmap(QPoint(opt.rect.x()+opt.rect.width()/2,opt.rect.y()+opt.rect.height()/3),px.scaled(opt.rect.width(),opt.rect.height()/2,Qt::KeepAspectRatio,Qt::SmoothTransformation));

    Thank you for this quick reminder!

    Cheers,
    A.

  • 0 Votes
    1 Posts
    259 Views
    No one has replied
  • 0 Votes
    4 Posts
    2k Views
    sierdzioS

    The model should provide this information for you. Create a role in the model which will return the correct value for any given cell. On QML side, just access that role and display it directly. No need for any get() method (which, by the way, is called data() https://doc.qt.io/qt-5/qabstractitemmodel.html#data, not get()).

  • 0 Votes
    3 Posts
    1k Views
    V

    This question was asked on stackoverflow as well. Just posting this here because the accepted answer was useful.

    Another approach would be to anchor the table below the header.

    TableView { id: tableView anchors.top: horizontalHeader.bottom model: TableModel { } }
  • 0 Votes
    5 Posts
    518 Views
    fcarneyF

    Make a role for Qt::DisplayRole and call it "display". Then return data by column like you are doing to support tables. If I remember correctly TableViews are stuck on using the display role. ListViews seem to be more flexible. I don't know why though. I had to use 2 methods to support both listviews and tableviews if I remember corrrectly.

    You should only have to use the word "display" to support this role in your delegates. You can add it as another case to your role case so you can support both types of views.

  • -1 Votes
    7 Posts
    932 Views
    Christian EhrlicherC

    Please take a look at your post above - do you really think we can read something meaningful out of it. Please use the <code> - tags to make it more readable and reduce your code as much as possible so only the problem and nothing else is in there.

  • 0 Votes
    2 Posts
    1k Views
    jsulmJ

    @Babs Take a look at https://wiki.qt.io/Handling_Microsoft_Excel_file_format

  • 0 Votes
    20 Posts
    2k Views
    D

    @jeremy_k Unfortunately, my MouseArea that covers the entire view and finds the delegate does not detect row insertion. For example on the picture below two rows surrounded with green were inserted (with beginInsertRows/endInsertRows) and MouseArea stopped responding to the clicks on the last two rows surrounded with red:

    alt text

    Below I provided the source code of the entire TableView as it is now in my project:

    TableView { id: table anchors.fill: parent columnSpacing: 5 rowSpacing: 3 clip: true property var columnWidths: [100, 80, 80, 20, 20, 20, 90, 90]; columnWidthProvider: function (column) { return columnWidths[column]; } property var rowHeight: 40 rowHeightProvider: function (column) { return rowHeight; } ScrollBar.horizontal: ScrollBar{} ScrollBar.vertical: ScrollBar{} ScrollIndicator.horizontal: ScrollIndicator { } ScrollIndicator.vertical: ScrollIndicator { } MouseArea { //id: ma anchors.fill: parent //hoverEnabled: true onClicked: { var index = Math.floor((mouse.y - table.originY) / (table.rowHeight + table.rowSpacing)); console.log("index:", index, " mouse: (", mouse.x, "," , mouse.y, ") table.origin: (", table.originX, ",", table.originY + ") table.content: (", table.contentX, ",", table.contentY + ")") var item = table.model.rowKey(index) if (item) window.openMarket(item) } } QtObject { id: enumSymbols property string spotAllowed: "S" property string marginAllowed: "M" property string isolatedMarginAllowed: "I" } delegate: DelegateChooser { role: "type" DelegateChoice { roleValue: "symbol" delegate: SymbolCell { item: model.item } } DelegateChoice { roleValue: "price" delegate: Text { horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignVCenter text: { var val = model.item[model.name]; return val ? val.toFixed(model.item.pricePrecision) : ""; } } } DelegateChoice { roleValue: "signal" delegate: Text { horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignVCenter text: TimeFormat.ago(model.item.signalTime, timeMachine.now) color: model.item.signalTime ? "black" : "gray" } } DelegateChoice { roleValue: "enum" delegate: Text { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter text: model.display ? enumSymbols[model.name] : "" color: "#1e73cd" } } DelegateChoice { roleValue: "zparams" delegate: Text { property var zparams: model.item[model.name] horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignVCenter text: zparams ? "(%1, %2, %3)".arg(zparams.lag).arg(zparams.threshold.toFixed(2)).arg(zparams.influence.toFixed(2)) : qsTr("No") color: zparams ? "black" : "gray" } } DelegateChoice { roleValue: "check" delegate: CheckBox { checked: model.item[model.name]; onClicked: { table.model.beginUpdateItem(model.item) model.item[model.name] = checked table.model.endUpdateItem(model.item) } } } DelegateChoice { delegate: Text { verticalAlignment: Text.AlignVCenter text: model.item[model.name] } } } }

    If I refresh my TableView with beginResetModel/endResetModel MouseArea starts to work correctly.

  • 0 Votes
    2 Posts
    833 Views
    nooneN

    my bad. I got answer in stack overflow

    The problem is caused by a naming conflict between the Button's display property and the role. The solution is to access the role through the model explicitly:

    delegate: Button { text: model.display }
  • 0 Votes
    5 Posts
    957 Views
    nooneN

    adding onWidthChanged: forceLayout() with columnWidthProvider to TableView works

  • 0 Votes
    5 Posts
    821 Views
    fcarneyF

    @jeanmilost Because of z ordering issues between delegates you will most likely need a popup.