首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法动态更改KDE等离子体5 Widget可扩展FullRepresentation组件的Component.onCompleted外大小

无法动态更改KDE等离子体5 Widget可扩展FullRepresentation组件的Component.onCompleted外大小
EN

Stack Overflow用户
提问于 2018-10-13 13:47:36
回答 1查看 405关注 0票数 1

我正在编写一个小部件的代码,可以通过单击它的FullRepresentation来扩展它:

代码语言:javascript
复制
                onClicked: {
                    plasmoid.expanded = !plasmoid.expanded 
                }

我有一个函数,可以更新其内容并将其放入Gridview中。update函数首先从Component.onCompleted调用,然后每次用户更新数据时调用它。问题是,我输入到可扩展的FullRepresentation中的数据可以包含不同数量的元素,我将这些元素放到网格视图中,并根据这个数字计算its和FullRepresentation的大小。

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

代码语言:javascript
复制
Item 
{
    id: fullRepresentation
    width: no_items > 2 ? 465 : no_items * 155
    height: Math.ceil(no_items / 3)* 155    
    property int no_items

...and --我只尝试从UpdateFunction中更改no_items属性,或者只尝试从UpdateFunction中运行这两个等式。

有办法绕过这件事吗?我也尝试过implicitHeight和implicitWidth属性。我真的很想能够动态地调整主可扩展表示的大小,不得不对其进行硬编码,然后有很多未填充的空间,感觉很糟糕。

编辑:下面是请求的示例:

Root.qml

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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()
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-23 07:35:29

嗯,我没有答案,但我自己想出来了。实际上,这似乎不可能使用完全表示的plasmoid.expanded方法,并产生其他错误,正如我在评论中提到的那样。

但是,您可以从代码中的任何位置动态调整窗口项的大小,因此这很好:

在Compact.qml中

代码语言:javascript
复制
    Full
    {  
        id: fullRep
    }  
    MouseArea
    {
        anchors.fill: parent
        onClicked: 
        {
            if (!fullRep.visible) fullRep.show()
            else fullRep.close()
        }
    }

Full.qml的启动

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52793599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档