无法动态更改 KDE Plasma 5 Widget 可扩展的完整表示组件大小超出 Component.onComple



我正在编写一个小部件,可以通过单击将其扩展为其完整表示:

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

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

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

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 属性。我真的希望能够动态调整主要可扩展表示的大小,必须对其进行硬编码然后有很多未填充的空间感觉很糟糕。

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

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.expand 方法,并且会产生其他错误,正如我在评论中提到的。

但是,您可以从代码中的任何位置动态调整 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

相关内容

最新更新