Opacity Widget

一般情况下,要移除界面中的某和控件只需要将控件代码删除即可,但是如果希望控件隐藏,但是控件之间占的位置依然保留,就需要使用Opacity来进行包裹.
并且还可以使用AnimatedOpacity添加动画,只需要加一个时长,在重新渲染时就会有一个渲染动画.是不是很酷呢.

在这里插入图片描述

import 'package:flutter/material.dart';

class GoogleOpacity extends StatefulWidget {
  @override
  GoogleOpacityState createState() => new GoogleOpacityState();
}

class GoogleOpacityState extends State<GoogleOpacity> {
  double _opacity = 1.0;

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Column(
          children: <Widget>[
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.red,
            ),
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.green,
            ),
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.blue,
            ),
          ],
        ),
        Column(
          children: <Widget>[
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.blue,
            ),
            Opacity(
              opacity: 0.0,
              child: Container(
                width: 100.0,
                height: 100.0,
                color: Colors.green,
              ),
            ),
            Container(
              width: 100.0,
              height: 100.0,
              color: Colors.red,
            ),
          ],
        ),
        Stack(
          children: <Widget>[
            Container(
              width: 200.0,
              height: 200.0,
              child: Image.network(
                  'http://img2.imgtn.bdimg.com/it/u=2755523882,2215399258&fm=200&gp=0.jpg'),
            ),
            AnimatedOpacity(
              duration: Duration(seconds: 1),
              opacity: _opacity,
              child: Container(
                width: 200.0,
                height: 200.0,
                color: Colors.blue,
              ),
            ),
          ],
        ),
      ],
    );
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    Future.delayed(Duration(seconds: 1), (){
      setState(() {
        _opacity = 0.0;
      });
    });
  }
}

我的博客
代码github

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import FreeCAD import FreeCADGui from PySide import QtGui, QtCore Gui.activateWorkbench("PartWorkbench") FreeCAD.newDocument() class SphereDialog(QtGui.QDialog): def __init__(self): super().__init__() self.setWindowTitle("Create Sphere") self.create_widgets() def create_widgets(self): layout = QtGui.QVBoxLayout() # Radius widget radius_label = QtGui.QLabel("Radius:") self.radius_spinbox = QtGui.QDoubleSpinBox() self.radius_spinbox.setMinimum(0.1) self.radius_spinbox.setMaximum(1000.0) self.radius_spinbox.setValue(10.0) layout.addWidget(radius_label) layout.addWidget(self.radius_spinbox) # Opacity widget opacity_label = QtGui.QLabel("Opacity:") self.opacity_slider = QtGui.QSlider(QtCore.Qt.Horizontal) self.opacity_slider.setMinimum(0) self.opacity_slider.setMaximum(100) self.opacity_slider.setValue(50) layout.addWidget(opacity_label) layout.addWidget(self.opacity_slider) # Create button create_button = QtGui.QPushButton("Create") create_button.clicked.connect(self.create_sphere) layout.addWidget(create_button) self.setLayout(layout) def create_sphere(self): # Get sphere parameters radius = self.radius_spinbox.value() opacity = float(self.opacity_slider.value() / 100) # Create sphere sphere = FreeCAD.ActiveDocument.addObject("Part::Sphere", "Sphere") sphere.Radius = radius sphere.ViewObject.Transparency = int(round(opacity * 100)) # Show in 3D view sphere.ViewObject.Visibility = True FreeCADGui.SendMsgToActiveView("ViewFit") FreeCADGui.Selection.clearSelection() FreeCADGui.Selection.addSelection(sphere) FreeCADGui.SendMsgToActiveView("ViewFit") # Close dialog self.close() dialog = SphereDialog() dialog.show()代码中执行没有球体出现,请修改代码
05-30

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值