2017-01-13 64 views
2

我遇到了一個問題,我希望是因爲我在編寫QML時不好,而不是因爲Qt中的一些基本錯誤。QML Applicationwindow調整stutter

每當我在水平方向調整應用程序窗口的大小(寬度更改)時,窗口不會調整到釋放鼠標的位置,但會「捕捉」回到其最小寬度。我已經設法將其解決到最基本的要求來重現錯誤。

  • 不釋放mousepress會導致寬度在最小寬度和鼠標所在的位置之間來回跳動。
  • 移除項目刪除錯誤
  • 垂直大小調整(改變高度)可以有時會崩潰的應用程序,如果鼠標未很長時間釋放(例如在調整大小的狀態)
  • 這實際上是不可能的調整大小因爲這

main.qml

import QtQuick 2.5 
import QtQuick.Window 2.2 
import QtQuick.Controls 1.4 

ApplicationWindow { 
    id: root 
    visible: true 
    minimumHeight: 768 
    minimumWidth: 1024 
    title: qsTr("Test") 
    color: "#292525" 

    Item { 
     width: 0.9*parent.width 
     height: 0.1*parent.height 
    } 
} 

任何想法,爲什麼發生這種情況?

回答

5

你有一種微妙的綁定循環的形式。 QtQuickControls'ApplicationWindow會嘗試保持窗口內容的大小與其內容的大小相匹配,稱爲contentItemApplicationWindow的所有子項都(默默)重新設置爲,但是您的內容大小取決於窗口它是居住在。

所以,你調整窗口的大小,從而改變你的Item的大小,從而改變contentItem的大小,這使得ApplicationWindow調整窗口的大小(與你戰鬥)。

像這樣的東西可能會奏效:

import QtQuick 2.5 
import QtQuick.Window 2.2 
import QtQuick.Controls 1.4 

ApplicationWindow { 
    id: root 

    visible: true 
    minimumHeight: 768 
    minimumWidth: 1024 
    title: qsTr("Test") 
    color: "#292525" 

    // This item will just match the Window's size... 
    Item { 
     anchors.fill: parent 

     // ... and here, we'll fill a part of it with a rectangle. 
     Rectangle { 
      color: "red" 
      width: 0.9*parent.width 
      height: 0.1*parent.height 
     } 
    } 
} 
+0

謝謝羅賓,我是不知道的結合環。 – arynaq

+0

或在挪威,Takk :) – arynaq

+0

裸露的凝膠! :) –