GUI学习之二十九—QInputDialog学习总结

最后一种对话框是QInputDialog,,用来提供个输入的窗口。

一常用的静态方法

  由于输入的类型不同,QInputDialog分为多种静态方法使用

#有步长调节器的整形数据,step为步长调节器的增量设定
QInputDialog.getInt(parent: QWidget, title: str, label: str, value: int = ..., min: int = ..., max: int = ..., step: int = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...)
#有步长调节器的浮点形数据,decimals为小数位数
QInputDialog.getDouble(parent: QWidget, title: str, label: str, value: float = ..., min: float = ..., max: float = ..., decimals: int = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...)
#单行文本数据,echo为输出模式(明文、密码或不显示)
QInputDialog.getText(parent: QWidget, title: str, label: str, echo: 'QLineEdit.EchoMode' = ..., text: str = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ..., inputMethodHints: typing.Union[QtCore.Qt.InputMethodHints, QtCore.Qt.InputMethodHint] = ...)
#多行文本
QInputDialog.getMultiLineText(parent: QWidget, title: str, label: str, text: str = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ..., inputMethodHints: typing.Union[QtCore.Qt.InputMethodHints, QtCore.Qt.InputMethodHint] = ...)
# #下拉列表,qizhong item为下拉列表的内容,迭代内从必须是字符串格式
QInputDialog.getItem(parent: QWidget, title: str, label: str, items: typing.Iterable[str], current: int = ..., editable: bool = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ..., inputMethodHints: typing.Union[QtCore.Qt.InputMethodHints, QtCore.Qt.InputMethodHint] = ...)

所有对话框都是有返回值的,返回的是个元祖,第一个元素就是input里对应的内容,第二个元素是个布尔量,如果对话框是按OK则返回1,取消就是返回0.

二.功能作用

  1.构造函数

QInputDialog(self, parent: typing.Optional[QWidget] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...)
Window = ...  # type: 'Qt.WindowType'
Dialog = ...  # type: 'Qt.WindowType'
Sheet = ...  # type: 'Qt.WindowType'
Drawer = ...  # type: 'Qt.WindowType'
Popup = ...  # type: 'Qt.WindowType'
Tool = ...  # type: 'Qt.WindowType'
ToolTip = ...  # type: 'Qt.WindowType'
SplashScreen = ...  # type: 'Qt.WindowType'
Desktop = ...  # type: 'Qt.WindowType'
SubWindow = ...  # type: 'Qt.WindowType'
WindowType_Mask = ...  # type: 'Qt.WindowType'
MSWindowsFixedSizeDialogHint = ...  # type: 'Qt.WindowType'
MSWindowsOwnDC = ...  # type: 'Qt.WindowType'
X11BypassWindowManagerHint = ...  # type: 'Qt.WindowType'
FramelessWindowHint = ...  # type: 'Qt.WindowType'
CustomizeWindowHint = ...  # type: 'Qt.WindowType'
WindowTitleHint = ...  # type: 'Qt.WindowType'
WindowSystemMenuHint = ...  # type: 'Qt.WindowType'
WindowMinimizeButtonHint = ...  # type: 'Qt.WindowType'
WindowMaximizeButtonHint = ...  # type: 'Qt.WindowType'
WindowMinMaxButtonsHint = ...  # type: 'Qt.WindowType'
WindowContextHelpButtonHint = ...  # type: 'Qt.WindowType'
WindowShadeButtonHint = ...  # type: 'Qt.WindowType'
WindowStaysOnTopHint = ...  # type: 'Qt.WindowType'
WindowOkButtonHint = ...  # type: 'Qt.WindowType'
WindowCancelButtonHint = ...  # type: 'Qt.WindowType'
WindowStaysOnBottomHint = ...  # type: 'Qt.WindowType'
WindowCloseButtonHint = ...  # type: 'Qt.WindowType'
MacWindowToolBarButtonHint = ...  # type: 'Qt.WindowType'
BypassGraphicsProxyWidget = ...  # type: 'Qt.WindowType'
WindowTransparentForInput = ...  # type: 'Qt.WindowType'
WindowOverridesSystemGestures = ...  # type: 'Qt.WindowType'
WindowDoesNotAcceptFocus = ...  # type: 'Qt.WindowType'
NoDropShadowWindowHint = ...  # type: 'Qt.WindowType'
WindowFullscreenButtonHint = ...  # type: 'Qt.WindowType'
ForeignWindow = ...  # type: 'Qt.WindowType'
BypassWindowManagerHint = ...  # type: 'Qt.WindowType'
CoverWindow = ...  # type: 'Qt.WindowType'
MaximizeUsingFullscreenGeometryHint = ...  # type: 'Qt.WindowType'
flag对应的枚举值

  要注意的就是flag(顶层窗口样式标志)对应的枚举值了。或者有几个最常用的效果在下面的setoption里也可以设置

  2.输入类型设置

QInputDialog.setInputMode(self, mode: 'QInputDialog.InputMode')
TextInput = ...  # type: 'QInputDialog.InputMode'
IntInput = ...  # type: 'QInputDialog.InputMode'
DoubleInput = ...  # type: 'QInputDialog.InputMode'

 主要要注意的是这里的类型里没有下拉列表,因为下拉列表是需要另外设置的

QInputDialog.setComboBoxItems(self, items: typing.Iterable[str])
QInputDialog.setComboBoxEditable()  #列表内容可编辑

  3.选项设置(输入类型)

QInputDialog.setOption(self, option: 'QInputDialog.InputDialogOption', on: bool = ...)
QInputDialog.setOptions(self, options: typing.Union[
'QInputDialog.InputDialogOptions', 'QInputDialog.InputDialogOption']) QInputDialog.testOption(self, option: 'QInputDialog.InputDialogOption') -> bool: ... QInputDialog.options()-> 'QInputDialog.InputDialogOptions': ...
NoButtons = ... # type: 'QInputDialog.InputDialogOption'
UseListViewForComboBoxItems = ... # type: 'QInputDialog.InputDialogOption'
UsePlainTextEditForTextInput = ... # type: 'QInputDialog.InputDialogOption'

  4.各种小分类的设置

QInputDialog.setIntMaximum()
QInputDialog.setIntMinimum()
QInputDialog.setIntRange()
QInputDialog.setIntStep()
QInputDialog.setIntValue()
整形数据
QInputDialog.setDoubleMaximum()
QInputDialog.setDoubleMinimum()
QInputDialog.setDoubleRange()
QInputDialog.setDoubleDecimals()
QInputDialog.setDoubleValue()
浮点型数据
QInputDialog.setTextEchoMode()
QInputDialog.setTextValue()
字符串类型

  小种类的设置一定要和输入数据类型设置是一样的。否则是没有效果的(输入类型设置优先级高。)

三.常用信号

QInputDialog.intValueChanged()
QInputDialog.intValueSelected()
QInputDialog.doubleValueChanged()
QInputDialog.doubleValueSelected()
QInputDialog.textValueChanged()
QInputDialog.textValueSelected()

注意下区别,changed是只要值发生改变(不需要确认选择),而Select是只有点击确认按钮后才触发。但是都传递值作为参数。

  

猜你喜欢

转载自www.cnblogs.com/yinsedeyinse/p/11575860.html