qiskit_classroom.result_image_dialog
image dialog
1""" 2 image dialog 3""" 4 5# Licensed to the Apache Software Foundation (ASF) under one 6# or more contributor license agreements. See the NOTICE file 7# distributed with this work for additional information 8# regarding copyright ownership. The ASF licenses this file 9# to you under the Apache License, Version 2.0 (the 10# "License"); you may not use this file except in compliance 11# with the License. You may obtain a copy of the License at 12# 13# http://www.apache.org/licenses/LICENSE-2.0 14# 15# Unless required by applicable law or agreed to in writing, 16# software distributed under the License is distributed on an 17# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18# KIND, either express or implied. See the License for the 19# specific language governing permissions and limitations 20# under the License. 21 22import shutil 23 24# pylint: disable=no-name-in-module 25from PySide6.QtWidgets import ( 26 QDialog, 27 QPushButton, 28 QVBoxLayout, 29 QLabel, 30 QFileDialog, 31 QHBoxLayout, 32) 33from PySide6.QtCore import Qt 34from PySide6.QtGui import QPixmap 35 36 37class ResultImageDialog(QDialog): 38 """ 39 show image which converted 40 """ 41 42 def __init__(self, parent) -> None: 43 super().__init__(parent) 44 self.image_path: str = "" 45 self.setWindowTitle("Result Image") 46 self.setMinimumWidth(300) 47 self.setMinimumHeight(200) 48 49 vbox = QVBoxLayout(self) 50 vbox.setAlignment(Qt.AlignmentFlag.AlignCenter) 51 self.image_label = QLabel() 52 vbox.addWidget(self.image_label) 53 54 hbox = QHBoxLayout() 55 56 self.close_button = QPushButton("close") 57 self.close_button.clicked.connect(self.close) 58 hbox.addWidget(self.close_button) 59 60 self.save_image = QPushButton("Save image") 61 self.save_image.clicked.connect(self.on_save_image_clicked) 62 hbox.addWidget(self.save_image) 63 64 vbox.addLayout(hbox) 65 66 def on_save_image_clicked(self) -> None: 67 """copy converted image""" 68 (path, _) = QFileDialog.getSaveFileName(self, "Image save", "", "Image (*.png)") 69 shutil.copyfile(self.image_path, path) 70 71 def show_image(self, image_path: str) -> None: 72 """show image 73 74 Args: 75 image_path (str): image path 76 """ 77 self.image_path = image_path 78 img = QPixmap(image_path) 79 self.image_label.setPixmap(img) 80 # resize dialog by image size 81 self.resize(img.width() + 100, img.height() + 150) 82 self.image_label.show() 83 self.show() 84 85 def hideEvent(self, event) -> None: # pylint: disable=invalid-name 86 """remove image 87 88 Args: 89 event (_type_): default event argument 90 """ 91 self.image_label.clear() 92 return super().hideEvent(event)
class
ResultImageDialog(PySide6.QtWidgets.QDialog):
38class ResultImageDialog(QDialog): 39 """ 40 show image which converted 41 """ 42 43 def __init__(self, parent) -> None: 44 super().__init__(parent) 45 self.image_path: str = "" 46 self.setWindowTitle("Result Image") 47 self.setMinimumWidth(300) 48 self.setMinimumHeight(200) 49 50 vbox = QVBoxLayout(self) 51 vbox.setAlignment(Qt.AlignmentFlag.AlignCenter) 52 self.image_label = QLabel() 53 vbox.addWidget(self.image_label) 54 55 hbox = QHBoxLayout() 56 57 self.close_button = QPushButton("close") 58 self.close_button.clicked.connect(self.close) 59 hbox.addWidget(self.close_button) 60 61 self.save_image = QPushButton("Save image") 62 self.save_image.clicked.connect(self.on_save_image_clicked) 63 hbox.addWidget(self.save_image) 64 65 vbox.addLayout(hbox) 66 67 def on_save_image_clicked(self) -> None: 68 """copy converted image""" 69 (path, _) = QFileDialog.getSaveFileName(self, "Image save", "", "Image (*.png)") 70 shutil.copyfile(self.image_path, path) 71 72 def show_image(self, image_path: str) -> None: 73 """show image 74 75 Args: 76 image_path (str): image path 77 """ 78 self.image_path = image_path 79 img = QPixmap(image_path) 80 self.image_label.setPixmap(img) 81 # resize dialog by image size 82 self.resize(img.width() + 100, img.height() + 150) 83 self.image_label.show() 84 self.show() 85 86 def hideEvent(self, event) -> None: # pylint: disable=invalid-name 87 """remove image 88 89 Args: 90 event (_type_): default event argument 91 """ 92 self.image_label.clear() 93 return super().hideEvent(event)
QDialog(self, parent: Optional[PySide6.QtWidgets.QWidget] = None, f: PySide6.QtCore.Qt.WindowType = Default(Qt.WindowFlags)) -> None
ResultImageDialog(parent)
43 def __init__(self, parent) -> None: 44 super().__init__(parent) 45 self.image_path: str = "" 46 self.setWindowTitle("Result Image") 47 self.setMinimumWidth(300) 48 self.setMinimumHeight(200) 49 50 vbox = QVBoxLayout(self) 51 vbox.setAlignment(Qt.AlignmentFlag.AlignCenter) 52 self.image_label = QLabel() 53 vbox.addWidget(self.image_label) 54 55 hbox = QHBoxLayout() 56 57 self.close_button = QPushButton("close") 58 self.close_button.clicked.connect(self.close) 59 hbox.addWidget(self.close_button) 60 61 self.save_image = QPushButton("Save image") 62 self.save_image.clicked.connect(self.on_save_image_clicked) 63 hbox.addWidget(self.save_image) 64 65 vbox.addLayout(hbox)
__init__(self, parent: Optional[PySide6.QtWidgets.QWidget] = None, f: PySide6.QtCore.Qt.WindowType = Default(Qt.WindowFlags)) -> None
Initialize self. See help(type(self)) for accurate signature.
def
on_save_image_clicked(self) -> None:
67 def on_save_image_clicked(self) -> None: 68 """copy converted image""" 69 (path, _) = QFileDialog.getSaveFileName(self, "Image save", "", "Image (*.png)") 70 shutil.copyfile(self.image_path, path)
copy converted image
def
show_image(self, image_path: str) -> None:
72 def show_image(self, image_path: str) -> None: 73 """show image 74 75 Args: 76 image_path (str): image path 77 """ 78 self.image_path = image_path 79 img = QPixmap(image_path) 80 self.image_label.setPixmap(img) 81 # resize dialog by image size 82 self.resize(img.width() + 100, img.height() + 150) 83 self.image_label.show() 84 self.show()
show image
Args: image_path (str): image path
def
hideEvent(self, event) -> None:
86 def hideEvent(self, event) -> None: # pylint: disable=invalid-name 87 """remove image 88 89 Args: 90 event (_type_): default event argument 91 """ 92 self.image_label.clear() 93 return super().hideEvent(event)
remove image
Args: event (_type_): default event argument
Inherited Members
- PySide6.QtWidgets.QDialog
- accept
- adjustPosition
- closeEvent
- contextMenuEvent
- done
- eventFilter
- exec
- exec_
- isSizeGripEnabled
- keyPressEvent
- minimumSizeHint
- open
- reject
- resizeEvent
- result
- setModal
- setResult
- setSizeGripEnabled
- setVisible
- showEvent
- sizeHint
- DialogCode
- rejected
- finished
- accepted
- PySide6.QtWidgets.QWidget
- acceptDrops
- accessibleDescription
- accessibleName
- actionEvent
- actions
- activateWindow
- addAction
- addActions
- adjustSize
- autoFillBackground
- backgroundRole
- backingStore
- baseSize
- changeEvent
- childAt
- childrenRect
- childrenRegion
- clearFocus
- clearMask
- close
- contentsMargins
- contentsRect
- contextMenuPolicy
- create
- createWinId
- createWindowContainer
- cursor
- destroy
- devType
- dragEnterEvent
- dragLeaveEvent
- dragMoveEvent
- dropEvent
- effectiveWinId
- ensurePolished
- enterEvent
- event
- find
- focusInEvent
- focusNextChild
- focusNextPrevChild
- focusOutEvent
- focusPolicy
- focusPreviousChild
- focusProxy
- focusWidget
- font
- fontInfo
- fontMetrics
- foregroundRole
- frameGeometry
- frameSize
- geometry
- grab
- grabGesture
- grabKeyboard
- grabMouse
- grabShortcut
- graphicsEffect
- graphicsProxyWidget
- hasFocus
- hasHeightForWidth
- hasMouseTracking
- hasTabletTracking
- height
- heightForWidth
- hide
- initPainter
- inputMethodEvent
- inputMethodHints
- inputMethodQuery
- insertAction
- insertActions
- internalWinId
- isActiveWindow
- isAncestorOf
- isEnabled
- isEnabledTo
- isFullScreen
- isHidden
- isLeftToRight
- isMaximized
- isMinimized
- isModal
- isRightToLeft
- isTopLevel
- isVisible
- isVisibleTo
- isWindow
- isWindowModified
- keyReleaseEvent
- keyboardGrabber
- layout
- layoutDirection
- leaveEvent
- locale
- lower
- mapFrom
- mapFromGlobal
- mapFromParent
- mapTo
- mapToGlobal
- mapToParent
- mask
- maximumHeight
- maximumSize
- maximumWidth
- metric
- minimumHeight
- minimumSize
- minimumWidth
- mouseDoubleClickEvent
- mouseGrabber
- mouseMoveEvent
- mousePressEvent
- mouseReleaseEvent
- move
- moveEvent
- nativeEvent
- nativeParentWidget
- nextInFocusChain
- normalGeometry
- overrideWindowFlags
- overrideWindowState
- paintEngine
- paintEvent
- palette
- parentWidget
- pos
- previousInFocusChain
- raise_
- rect
- redirected
- releaseKeyboard
- releaseMouse
- releaseShortcut
- removeAction
- render
- repaint
- resize
- restoreGeometry
- saveGeometry
- screen
- scroll
- setAcceptDrops
- setAccessibleDescription
- setAccessibleName
- setAttribute
- setAutoFillBackground
- setBackgroundRole
- setBaseSize
- setContentsMargins
- setContextMenuPolicy
- setCursor
- setDisabled
- setEnabled
- setFixedHeight
- setFixedSize
- setFixedWidth
- setFocus
- setFocusPolicy
- setFocusProxy
- setFont
- setForegroundRole
- setGeometry
- setGraphicsEffect
- setHidden
- setInputMethodHints
- setLayout
- setLayoutDirection
- setLocale
- setMask
- setMaximumHeight
- setMaximumSize
- setMaximumWidth
- setMinimumHeight
- setMinimumSize
- setMinimumWidth
- setMouseTracking
- setPalette
- setParent
- setScreen
- setShortcutAutoRepeat
- setShortcutEnabled
- setSizeIncrement
- setSizePolicy
- setStatusTip
- setStyle
- setStyleSheet
- setTabOrder
- setTabletTracking
- setToolTip
- setToolTipDuration
- setUpdatesEnabled
- setWhatsThis
- setWindowFilePath
- setWindowFlag
- setWindowFlags
- setWindowIcon
- setWindowIconText
- setWindowModality
- setWindowModified
- setWindowOpacity
- setWindowRole
- setWindowState
- setWindowTitle
- show
- showFullScreen
- showMaximized
- showMinimized
- showNormal
- size
- sizeIncrement
- sizePolicy
- stackUnder
- statusTip
- style
- styleSheet
- tabletEvent
- testAttribute
- toolTip
- toolTipDuration
- topLevelWidget
- underMouse
- ungrabGesture
- unsetCursor
- unsetLayoutDirection
- unsetLocale
- update
- updateGeometry
- updateMicroFocus
- updatesEnabled
- visibleRegion
- whatsThis
- wheelEvent
- width
- winId
- window
- windowFilePath
- windowFlags
- windowHandle
- windowIcon
- windowIconText
- windowModality
- windowOpacity
- windowRole
- windowState
- windowTitle
- windowType
- x
- y
- RenderFlag
- windowIconTextChanged
- windowIconChanged
- windowTitleChanged
- customContextMenuRequested
- PySide6.QtCore.QObject
- blockSignals
- childEvent
- children
- connect
- connectNotify
- customEvent
- deleteLater
- disconnect
- disconnectNotify
- dumpObjectInfo
- dumpObjectTree
- dynamicPropertyNames
- emit
- findChild
- findChildren
- inherits
- installEventFilter
- isQuickItemType
- isSignalConnected
- isWidgetType
- isWindowType
- killTimer
- metaObject
- moveToThread
- objectName
- parent
- property
- receivers
- removeEventFilter
- sender
- senderSignalIndex
- setObjectName
- setProperty
- signalsBlocked
- startTimer
- thread
- timerEvent
- tr
- destroyed
- objectNameChanged
- PySide6.QtGui.QPaintDevice
- colorCount
- depth
- devicePixelRatio
- devicePixelRatioF
- devicePixelRatioFScale
- heightMM
- logicalDpiX
- logicalDpiY
- paintingActive
- physicalDpiX
- physicalDpiY
- widthMM
- painters
- PaintDeviceMetric