我正在编写一个小部件的代码,可以通过单击它的FullRepresentation来扩展它:
onClicked: {
plasmoid.expanded = !plasmoid.expanded
}我有一个函数,可以更新其内容并将其放入Gridview中。update函数首先从Component.onCompleted调用,然后每次用户更新数据时调用它。问题是,我输入到可扩展的FullRepresentation中的数据可以包含不同数量的元素,我将这些元素放到网格视图中,并根据这个数字计算its和FullRepresentation的大小。
但是,我发现我只能从Component.onCompleted块中指定表示的大小。当我在外部调用update函数时,它不会更改大小,无论大小是否在item属性中定义,如下所示:
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
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()
}
}发布于 2018-10-23 07:35:29
嗯,我没有答案,但我自己想出来了。实际上,这似乎不可能使用完全表示的plasmoid.expanded方法,并产生其他错误,正如我在评论中提到的那样。
但是,您可以从代码中的任何位置动态调整窗口项的大小,因此这很好:
在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 methodhttps://stackoverflow.com/questions/52793599
复制相似问题