diff --git a/qml/xqtableview.qml b/qml/xqtableview.qml deleted file mode 100644 index 01e1d3d..0000000 --- a/qml/xqtableview.qml +++ /dev/null @@ -1,65 +0,0 @@ -import QtQuick -import QtQuick.Controls -import QtQuick.Layouts - -Window -{ - width: 640 - height: 480 - visible: true - title: qsTr("StringListModel") - - TableView - { - id: childTableView - anchors.fill: parent - - model: myChildModel // z. B. QStandardItemModel mit 9 Spalten - - delegate: Rectangle - { - required property string display - - //height: 5 - //width: childTableView.width - color : "blue" - border.color: "#ccc" - width: childTableView.width; - - RowLayout - { - anchors.fill: parent - anchors.margins: 2 - - TextField - { - text : display - font.pixelSize: 10 - Layout.fillWidth: true - - background: Rectangle - { - color : "white" - } - - onEditingFinished: - { - console.log("Editing finished, new text is :"+ text + " at index :" + index) - model.names = text //The roles here are defined in model class - } - } - } - - } - - ScrollBar.horizontal: ScrollBar {} - ScrollBar.vertical: ScrollBar {} - - // // Optional: Spaltenbreiten setzen - // onModelChanged: { - // for (let i = 0; i < model.columns; ++i) - // table.setColumnWidth(i, 100) - // } - } - -} diff --git a/qml/xqtreeview.qml b/qml/xqtreeview.qml index 3d65da9..a4b3be9 100644 --- a/qml/xqtreeview.qml +++ b/qml/xqtreeview.qml @@ -30,14 +30,30 @@ TreeView implicitHeight: 20 border.color: "#cccccc" //color: index % 2 === 0 ? "#f9f9f9" : "#e0e0e0" - color: TreeView.isSelected ? "#d0eaff" : (row % 2 === 0 ? "#f9f9f9" : "#ffffff") + //color: TreeView.isSelected ? "#d0eaff" : (row % 2 === 0 ? "#f9f9f9" : "#ffffff") + //color: TreeView.isSelected ? "#d0eaff" : (row % 2 === 0 ? "#f9f9f9" : "#ffffff") - Text + TextField { + id: entry anchors.centerIn: parent text: display font.pixelSize: 12 + + background: Rectangle + { + //color: entry.enabled ? "transparent" : "#353637" + //border.color: entry.enabled ? "#21be2b" : "transparent" + border.color: "transparent" + } + + onEditingFinished: + { + console.log("Editing finished, new text is :"+ text + " at index :" + index) + model.display = text //The roles here are defined in model class + } } + } ScrollBar.horizontal: ScrollBar {} diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index 70f8976..c7f8cee 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -112,7 +112,7 @@ void XQMainWindow::initMainWindow() // #2. load demo data loadDocument( c_DocumentFileName1 ); - //loadDocumentQML( c_DocumentFileName2 ); + loadDocumentQML( c_DocumentFileName2 ); //loadDocument( c_DocumentFileName2 ); //loadDocument( c_DocumentFileName3 ); diff --git a/src/items/xqitemdelegate.cpp b/src/items/xqitemdelegate.cpp index 8d33c11..aef7a27 100644 --- a/src/items/xqitemdelegate.cpp +++ b/src/items/xqitemdelegate.cpp @@ -119,6 +119,29 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt { QStyleOptionHeader headerOption; +/* + QWidget* srcWidget = nullptr; + const QTreeView* treeView = qobject_cast(option.widget); + if (treeView != nullptr) + { + srcWidget = (QWidget*)treeView; + // is never nullptr !? + if (treeView->header() != nullptr) + { + // use the header as "parent" for style init + srcWidget = treeView->header(); + } + headerOption.initFrom(srcWidget); + headerOption.text = "FIRZ";//index.data(Qt::DisplayRole).toString(); + headerOption.rect = option.rect; + headerOption.styleObject = option.styleObject; + // __ch: reduce inner offset when painting + headerOption.textAlignment |= Qt::AlignVCenter; + + // -- + } +*/ + // use the header as "parent" for style init QWidget* srcWidget = treeTable();//->header(); headerOption.initFrom(srcWidget); @@ -129,11 +152,13 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt headerOption.textAlignment |= Qt::AlignVCenter; headerOption.icon = item.icon(); + // save painter painter->save(); + QStyle* widgetStyle = srcWidget->style(); - widgetStyle->drawControl(QStyle::CE_Header, &headerOption, painter, srcWidget); + QApplication::style()->drawControl(QStyle::CE_Header, &headerOption, painter, srcWidget); // restore painter painter->restore(); @@ -254,6 +279,8 @@ QSize XQItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelI QWidget* XQItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { + Q_UNUSED(option); + XQItem& item = xqItemFromIndex(index); XQItem::EditorType edType = item.editorType(); if( edType == XQItem::NoEditorType ) diff --git a/src/xtree.qrc b/src/xtree.qrc index 7df0b75..ef4aeec 100644 --- a/src/xtree.qrc +++ b/src/xtree.qrc @@ -4,7 +4,6 @@ ../xml/modeldata2.xtr ../xml/modeldata3.xtr ../xml/modelsheets.xml - ../qml/xqtableview.qml ../qml/xqtreeview.qml diff --git a/xml/modeldata1.xtr b/xml/modeldata1.xtr index a53cecb..4a15fda 100644 --- a/xml/modeldata1.xtr +++ b/xml/modeldata1.xtr @@ -15,9 +15,8 @@ - - - + + diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index f473ab7..62de50f 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -129,7 +129,12 @@ - + + + + + +