无法在 Component.onCompleted 之外动态更改 KDE Plasma 5 Widget Expandable FullRepresentation Component 大小

Unable to dynamically change KDE Plasma 5 Widget Expandable FullRepresentation Component size outside of Component.onCompleted

我正在编写一个小部件,可以通过单击将其展开为 FullRepresentation:

                onClicked: {
                    plasmoid.expanded = !plasmoid.expanded 
                }

我有一个更新其内容并将它们放入 Gridview 的函数。 update 函数首先从 Component.onCompleted 调用,但之后每次用户更新数据时我都会调用它。问题是我输入可扩展的 FullRepresentation 的数据可能包含不同数量的元素,我将这些元素放入 gridview 并根据此数字计算其 AND FullRepresentation 的大小。

但是,我发现我只能从 Component.onCompleted 块中指定表示的大小。当我在它外面调用更新函数时,它不会改变大小,无论大小是否在项目属性中定义如下:

Item 
{
    id: fullRepresentation
    width: no_items > 2 ? 465 : no_items * 155
    height: Math.ceil(no_items / 3)* 155    
    property int no_items

...我只尝试更改 UpdateFunction 中的 no_items 属性,或者只是尝试 运行 中的两个方程。

有什么办法解决这个问题吗?我还尝试了 implicitHeight 和 implicitWidth 属性。我真的很想能够动态调整主要可扩展表示的大小,不得不对其进行硬编码然后有很多未填充的感觉很糟糕 space.

编辑: 这是请求的示例:

Root.qml

import org.kde.plasma.plasmoid 2.0
import QtQuick 2.2

Item
{
    id: root
    width: 185; height: 185
    Plasmoid.compactRepresentation: Compact {}
    Plasmoid.fullRepresentation: Full {}
    Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
    signal addItems() 
}

Compact.qml

import QtQuick 2.2

Item
{
    Rectangle
    {      
        width: root.width; height: root.height
        MouseArea
        {
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton | Qt.RightButton
            onClicked: if (mouse.button == Qt.RightButton) root.addItems()
                       else plasmoid.expanded = !plasmoid.expanded
        }
    }
}

Full.qml

import QtQuick 2.2

Item 
{
    width: no_items > 2 ? 465 : no_items * 155
    height: Math.ceil(no_items / 3)* 155    
    property int no_items : 0
    function redrawGridView()  
    {        
        readingListModel.clear()       
        var i
        for (i = 0; i < no_items; i++) readingListModel.append({})                
    }     
    function addItems()
    {
        no_items = 6
        width = no_items > 2 ? 465 : no_items * 155
        height = Math.ceil(no_items / 3)* 155    
        redrawGridView()
    }

    ListModel 
    {
        id: readingListModel
    }

    GridView 
    { 
        id: readingGridView
        width: count > 2 ? 465 : count * 155
        height: Math.ceil(count/3) * 155
        cellWidth: 155; cellHeight: 155
        model: readingListModel
        delegate: Rectangle
        {                  
            width: 150; height: 150;
        }
    }

   Component.onCompleted:
    {            
        root.addItems.connect(addItems)    
        no_items = 3  
        redrawGridView()
    }
}

好吧,我没有得到答案,但我自己已经弄明白了。 实际上,正如我在评论中提到的那样,使用具有完整表示的 plasmoid.expanded 方法似乎是不可能的,并且会产生其他错误。

但是您可以在代码中的任何位置动态调整 Window 项目大小,所以这很好用:

在Compact.qml

    Full
    {  
        id: fullRep
    }  
    MouseArea
    {
        anchors.fill: parent
        onClicked: 
        {
            if (!fullRep.visible) fullRep.show()
            else fullRep.close()
        }
    }

Full.qml

开始
Window
{
    x: 100;y: 100
    width: 465;height: 195
    color: theme.backgroundColor
    flags: Qt.FramelessWindowHint //You can make it frameless like the expandable  
                                 //representation is when using the previous method