Py学习  »  tornado

TornadoFx透明视图

Balage1551 • 6 年前 • 1578 次点击  

我想创建一个具有部分透明背景的视图(阶段、窗口)。我有个包含alpha通道的图像

an image containing alpha channel

我在javafx中使用了这种场景,我必须将场景填充设置为空,并将根节点背景色设置为透明。我也尝试过龙卷风:

class NextRoundView : View("Következő kör") {

    override val root = vbox {
        style {
            backgroundColor = multi(Color.TRANSPARENT)
            backgroundImage = multi(URI.create("/common/rope-bg-500x300.png"))
            backgroundRepeat = multi(BackgroundRepeat.NO_REPEAT 
                                  to BackgroundRepeat.NO_REPEAT)
        }
        prefWidth = 500.0
        prefHeight = 300.0

        spacing = 20.0
        padding = insets(50, 20)
        text("A text") {
            font = Font.font(40.0)
            alignment = Pos.CENTER
        }

        button("OK")
        {
            font = Font.font(20.0)
            action {
                close()
            }
        }
        sceneProperty().addListener{ _,_,n ->
            n.fill = null
        }
    }

}

我这样称呼这个观点:

NextRoundView().apply { 
    openModal(stageStyle = StageStyle.TRANSPARENT, block = true) 
}

然而,该阶段仍有背景:

enter image description here

我错过了什么?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/30819
 
1578 次点击  
文章 [ 1 ]  |  最新文章 6 年前
Edvin Syse
Reply   •   1 楼
Edvin Syse    6 年前

你犯了几个错误,导致了这一点。首先,决不能手动实例化uicomponents(view,fragment)。这样做会使他们错过重要的生命周期回调。一个重要的回调是 onDock 这是操作指定场景的最佳位置。更改这两个问题并清除某些语法将导致此代码,这成功地使背景透明:

class MyApp : App(MyView::class)

class MyView : View() {
    override val root = stackpane {
        button("open").action {
            find<NextRoundView>().openModal(stageStyle = StageStyle.TRANSPARENT, block = true)
        }
    }
}

class NextRoundView : View("Következő kör") {
    override val root = vbox {
        style {
            backgroundColor += Color.TRANSPARENT
            backgroundImage += URI.create("/common/rope-bg-500x300.png")
            backgroundRepeat += BackgroundRepeat.NO_REPEAT to BackgroundRepeat.NO_REPEAT
        }
        prefWidth = 500.0
        prefHeight = 300.0

        spacing = 20.0
        padding = insets(50, 20)
        text("A text") {
            font = Font.font(40.0)
            alignment = Pos.CENTER
        }

        button("OK") {
            font = Font.font(20.0)
            action {
                close()
            }
        }
    }

    override fun onDock() {
        currentStage?.scene?.fill = null
    }
}

以下是应用程序的屏幕截图,其中包含实现的更改:

enter image description here