2016/7/20 1:14:45 PyQT5 实现点击隐藏,展开效果

2016/7/20 1:14:45
986998-20160906104420535-1424710418.jpg
code
 
   
  1. #!/usr/bin/env python
  2. #############################################################################
  3. ##
  4. ## Copyright (C) 2013 Riverbank Computing Limited.
  5. ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
  6. ## All rights reserved.
  7. ##
  8. ## This file is part of the examples of PyQt.
  9. ##
  10. ## $QT_BEGIN_LICENSE:BSD$
  11. ## You may use this file under the terms of the BSD license as follows:
  12. ##
  13. ## "Redistribution and use in source and binary forms, with or without
  14. ## modification, are permitted provided that the following conditions are
  15. ## met:
  16. ## * Redistributions of source code must retain the above copyright
  17. ## notice, this list of conditions and the following disclaimer.
  18. ## * Redistributions in binary form must reproduce the above copyright
  19. ## notice, this list of conditions and the following disclaimer in
  20. ## the documentation and/or other materials provided with the
  21. ## distribution.
  22. ## * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
  23. ## the names of its contributors may be used to endorse or promote
  24. ## products derived from this software without specific prior written
  25. ## permission.
  26. ##
  27. ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. ## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. ## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. ## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. ## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  34. ## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  35. ## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. ## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  38. ## $QT_END_LICENSE$
  39. ##
  40. #############################################################################
  41. from PyQt5.QtCore import Qt
  42. from PyQt5.QtWidgets import (QApplication, QCheckBox, QDialog,
  43. QDialogButtonBox, QGridLayout, QHBoxLayout, QLabel, QLayout, QLineEdit,
  44. QPushButton, QVBoxLayout, QWidget)
  45. class FindDialog(QDialog):
  46. def __init__(self, parent=None):
  47. super(FindDialog, self).__init__(parent)
  48. label = QLabel("Find &what:")
  49. lineEdit = QLineEdit()
  50. label.setBuddy(lineEdit)
  51. caseCheckBox = QCheckBox("Match &case")
  52. fromStartCheckBox = QCheckBox("Search from &start")
  53. fromStartCheckBox.setChecked(True)
  54. findButton = QPushButton("&Find")
  55. findButton.setDefault(True)
  56. moreButton = QPushButton("&More")
  57. moreButton.setCheckable(True)
  58. moreButton.setAutoDefault(False)
  59. extension = QWidget()
  60. wholeWordsCheckBox = QCheckBox("&Whole words")
  61. backwardCheckBox = QCheckBox("Search &backward")
  62. searchSelectionCheckBox = QCheckBox("Search se&lection")
  63. buttonBox = QDialogButtonBox(Qt.Vertical)
  64. buttonBox.addButton(findButton, QDialogButtonBox.ActionRole)
  65. buttonBox.addButton(moreButton, QDialogButtonBox.ActionRole)
  66. moreButton.toggled.connect(extension.setVisible)
  67. extensionLayout = QVBoxLayout()
  68. extensionLayout.setContentsMargins(0, 0, 0, 0)
  69. extensionLayout.addWidget(wholeWordsCheckBox)
  70. extensionLayout.addWidget(backwardCheckBox)
  71. extensionLayout.addWidget(searchSelectionCheckBox)
  72. extension.setLayout(extensionLayout)
  73. topLeftLayout = QHBoxLayout()
  74. topLeftLayout.addWidget(label)
  75. topLeftLayout.addWidget(lineEdit)
  76. leftLayout = QVBoxLayout()
  77. leftLayout.addLayout(topLeftLayout)
  78. leftLayout.addWidget(caseCheckBox)
  79. leftLayout.addWidget(fromStartCheckBox)
  80. mainLayout = QGridLayout()
  81. #关键性的参数设置
  82. mainLayout.setSizeConstraint(QLayout.SetFixedSize)
  83. mainLayout.addLayout(leftLayout, 0, 0)
  84. mainLayout.addWidget(buttonBox, 0, 1)
  85. mainLayout.addWidget(extension, 1, 0, 1, 2)
  86. mainLayout.setRowStretch(2, 1)
  87. self.setLayout(mainLayout)
  88. self.setWindowTitle("Extension")
  89. extension.hide()
  90. if __name__ == '__main__':
  91. import sys
  92. app = QApplication(sys.argv)
  93. dialog = FindDialog()
  94. dialog.show()
  95. sys.exit(app.exec_())





转载于:https://www.cnblogs.com/topshooter/p/5844850.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值