TableView Resizing Columns Signal
-
hey, I'm kind of new to qml and Im trying to find what signal is being emitted when resizing a column in table view.
up until now I used the WidthChanged signal, but the thing is, I want to change other columns after resizing a specific column.
I want to make the table to always fit the screen, even when resizing, so I guess I need to know when I'm resizing and not just when the column width is changed, because then every time I will resize a column the Colum which his width will also change as a result will emit the signal as well (and so on...) and I will get unwanted behavior.here is an example of a table that fills the entire window with resizable Columns.
im attaching the qml file, the main.cpp and the tableModel.hMain.qml :
import QtQuick import QtQuick.Controls import QtQuick.Window ApplicationWindow { id: mainWindow width: 800 height: 600 visible: true TableView { id: tableViewid width: parent.width height: parent.height boundsBehavior: Flickable.StopAtBounds columnSpacing: 1 rowSpacing: 1 clip: true resizableColumns: true model: tableModel // Use the context property 'tableModel' delegate: Rectangle { implicitWidth: (mainWindow.width-(tableViewid.rowSpacing*tableModel.columnCount()))/tableModel.columnCount() implicitHeight: 50 Text { text: display } } } }
main.cpp :
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQmlContext> #include "../TableViewPlayGround/tablemodel.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); qmlRegisterType<TableModel>("example.com", 1, 0, "tableModel"); QQmlApplicationEngine engine; QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.loadFromModule("TableViewPlayGround", "Main"); TableModel* model = new TableModel(); engine.rootContext()->setContextProperty(QString("tableModel"), model); return app.exec(); }
tablemodel.h :
#include <qqml.h> #include <QAbstractTableModel> class TableModel : public QAbstractTableModel { Q_OBJECT QML_ELEMENT QML_ADDED_IN_VERSION(1, 1) public: TableModel() { for (int i = 1; i <= 50; ++i) { elements.append(i); } } int rowCount(const QModelIndex & = QModelIndex()) const override { return elements.size() / 5 + (elements.size() % 5 != 0); } int columnCount(const QModelIndex & = QModelIndex()) const override { return 5; } QVariant data(const QModelIndex &index, int role) const override { int elementIndex = index.row() * 5 + index.column(); if (elementIndex < elements.size() && role == Qt::DisplayRole) { return QString("%1").arg(elements[elementIndex]); } return QVariant(); } QHash<int, QByteArray> roleNames() const override { return { {Qt::DisplayRole, "display"} }; } private: QList<int> elements; };
thanks in advance for the help!