当前位置: 首页>>代码示例>>Python>>正文


Python QScrollArea.horizontalScrollBar方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QScrollArea.horizontalScrollBar方法的典型用法代码示例。如果您正苦于以下问题:Python QScrollArea.horizontalScrollBar方法的具体用法?Python QScrollArea.horizontalScrollBar怎么用?Python QScrollArea.horizontalScrollBar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QScrollArea的用法示例。


在下文中一共展示了QScrollArea.horizontalScrollBar方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ConfigurationWidget

# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import horizontalScrollBar [as 别名]

#.........这里部分代码省略.........
            try:
                page.setMode(self.displayMode)
            except AttributeError:
                pass
        return page
        
    def showConfigurationPageByName(self, pageName, setCurrent=True):
        """
        Public slot to show a named configuration page.
        
        @param pageName name of the configuration page to show (string)
        @param setCurrent flag indicating to set the current item (boolean)
        """
        if pageName == "empty" or pageName not in self.configItems:
            page = self.emptyPage
        else:
            pageData = self.configItems[pageName]
            if pageData[-1] is None and pageData[2] is not None:
                # the page was not loaded yet, create it
                page = self.__initPage(pageData)
            else:
                page = pageData[-1]
            if page is None:
                page = self.emptyPage
            elif setCurrent:
                items = self.configList.findItems(
                    pageData[0],
                    Qt.MatchFixedString | Qt.MatchRecursive)
                for item in items:
                    if item.data(0, Qt.UserRole) == pageName:
                        self.configList.setCurrentItem(item)
        self.configStack.setCurrentWidget(page)
        ssize = self.scrollArea.size()
        if self.scrollArea.horizontalScrollBar():
            ssize.setHeight(
                ssize.height() -
                self.scrollArea.horizontalScrollBar().height() - 2)
        if self.scrollArea.verticalScrollBar():
            ssize.setWidth(
                ssize.width() -
                self.scrollArea.verticalScrollBar().width() - 2)
        psize = page.minimumSizeHint()
        self.configStack.resize(max(ssize.width(), psize.width()),
                                max(ssize.height(), psize.height()))
        
        if page != self.emptyPage:
            page.polishPage()
            self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(True)
            self.buttonBox.button(QDialogButtonBox.Reset).setEnabled(True)
        else:
            self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(False)
            self.buttonBox.button(QDialogButtonBox.Reset).setEnabled(False)
        
        # reset scrollbars
        for sb in [self.scrollArea.horizontalScrollBar(),
                   self.scrollArea.verticalScrollBar()]:
            if sb:
                sb.setValue(0)
        
        self.__currentConfigurationPageName = pageName
        
    def getConfigurationPageName(self):
        """
        Public method to get the page name of the current page.
        
        @return page name of the current page (string)
开发者ID:pycom,项目名称:EricShort,代码行数:70,代码来源:ConfigurationDialog.py

示例2: SearchReplaceSlidingWidget

# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import horizontalScrollBar [as 别名]

#.........这里部分代码省略.........
        self.__rightButton.clicked.connect(self.__slideRight)
    
    def changeEvent(self, evt):
        """
        Protected method handling state changes.

        @param evt event containing the state change (QEvent)
        """
        if evt.type() == QEvent.FontChange:
            self.setMaximumHeight(
                self.__searchReplaceWidget.sizeHint().height())
            self.adjustSize()
    
    def findNext(self):
        """
        Public slot to find the next occurrence of text.
        """
        self.__searchReplaceWidget.findNext()
    
    def findPrev(self):
        """
        Public slot to find the next previous of text.
        """
        self.__searchReplaceWidget.findPrev()
    
    def selectionChanged(self):
        """
        Public slot tracking changes of selected text.
        """
        editor = self.sender()
        self.__searchReplaceWidget.updateSelectionCheckBox(editor)
    
    @pyqtSlot(Editor)
    def updateSelectionCheckBox(self, editor):
        """
        Public slot to update the selection check box.
        
        @param editor reference to the editor (Editor)
        """
        self.__searchReplaceWidget.updateSelectionCheckBox(editor)

    def show(self, text=''):
        """
        Public slot to show the widget.
        
        @param text text to be shown in the findtext edit (string)
        """
        self.__searchReplaceWidget.show(text)
        super(SearchReplaceSlidingWidget, self).show()
        self.__enableScrollerButtons()
    
    def __slideLeft(self):
        """
        Private slot to move the widget to the left, i.e. show contents to the
        right.
        """
        self.__slide(True)
    
    def __slideRight(self):
        """
        Private slot to move the widget to the right, i.e. show contents to
        the left.
        """
        self.__slide(False)
    
    def __slide(self, toLeft):
        """
        Private method to move the sliding widget.
        
        @param toLeft flag indicating to move to the left (boolean)
        """
        scrollBar = self.__scroller.horizontalScrollBar()
        stepSize = scrollBar.singleStep()
        if toLeft:
            stepSize = -stepSize
        newValue = scrollBar.value() + stepSize
        if newValue < 0:
            newValue = 0
        elif newValue > scrollBar.maximum():
            newValue = scrollBar.maximum()
        scrollBar.setValue(newValue)
        self.__enableScrollerButtons()
    
    def __enableScrollerButtons(self):
        """
        Private method to set the enabled state of the scroll buttons.
        """
        scrollBar = self.__scroller.horizontalScrollBar()
        self.__leftButton.setEnabled(scrollBar.value() > 0)
        self.__rightButton.setEnabled(scrollBar.value() < scrollBar.maximum())
    
    def resizeEvent(self, evt):
        """
        Protected method to handle resize events.
        
        @param evt reference to the resize event (QResizeEvent)
        """
        self.__enableScrollerButtons()
        
        super(SearchReplaceSlidingWidget, self).resizeEvent(evt)
开发者ID:testmana2,项目名称:test,代码行数:104,代码来源:SearchReplaceWidget.py

示例3: PixmapDiagram

# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import horizontalScrollBar [as 别名]

#.........这里部分代码省略.........
        @param factor factor to adjust by (float)
        """
        scrollBar.setValue(int(factor * scrollBar.value()
                           + ((factor - 1) * scrollBar.pageStep() / 2)))
        
    def __levelForZoom(self, zoom):
        """
        Private method determining the zoom level index given a zoom factor.
        
        @param zoom zoom factor (integer)
        @return index of zoom factor (integer)
        """
        try:
            index = PixmapDiagram.ZoomLevels.index(zoom)
        except ValueError:
            for index in range(len(PixmapDiagram.ZoomLevels)):
                if zoom <= PixmapDiagram.ZoomLevels[index]:
                    break
        return index
    
    def __doZoom(self, value):
        """
        Private method to set the zoom value in percent.
        
        @param value zoom value in percent (integer)
        """
        oldValue = self.__zoom()
        if value != oldValue:
            self.pixmapLabel.resize(
                value / 100 * self.pixmapLabel.pixmap().size())
            
            factor = value / oldValue
            self.__adjustScrollBar(
                self.pixmapView.horizontalScrollBar(), factor)
            self.__adjustScrollBar(
                self.pixmapView.verticalScrollBar(), factor)
            
            self.__zoomWidget.setValue(value)
        
    def __zoomIn(self):
        """
        Private method to zoom into the pixmap.
        """
        index = self.__levelForZoom(self.__zoom())
        if index < len(PixmapDiagram.ZoomLevels) - 1:
            self.__doZoom(PixmapDiagram.ZoomLevels[index + 1])
        
    def __zoomOut(self):
        """
        Private method to zoom out of the pixmap.
        """
        index = self.__levelForZoom(self.__zoom())
        if index > 0:
            self.__doZoom(PixmapDiagram.ZoomLevels[index - 1])
        
    def __zoomReset(self):
        """
        Private method to reset the zoom value.
        """
        self.__doZoom(PixmapDiagram.ZoomLevels[PixmapDiagram.ZoomLevelDefault])
        
    def __zoom(self):
        """
        Private method to get the current zoom factor in percent.
        
        @return current zoom factor in percent (integer)
开发者ID:testmana2,项目名称:test,代码行数:70,代码来源:PixmapDiagram.py

示例4: GlyphView

# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import horizontalScrollBar [as 别名]

#.........这里部分代码省略.........
        self._currentTool.paint(painter)
        painter.restore()

    def scrollArea(self):
        return self._scrollArea

    def sizeHint(self):
        viewport = self._scrollArea.viewport()
        scrollWidth, scrollHeight = viewport.width(), viewport.height()
        # pick the width and height
        glyphWidth, glyphHeight = self._getGlyphWidthHeight()
        glyphWidth = glyphWidth * self._scale
        glyphHeight = glyphHeight * self._scale
        xOffset = 1000 * 2 * self._scale
        yOffset = xOffset
        width = glyphWidth + xOffset
        height = glyphHeight + yOffset
        if scrollWidth > width:
            width = scrollWidth
        if scrollHeight > height:
            height = scrollHeight
        # calculate and store the vertical centering offset
        self._verticalCenterYBuffer = (height - glyphHeight) / 2.0
        return QSize(width, height)

    def resizeEvent(self, event):
        self.adjustSize()
        event.accept()

    def showEvent(self, event):
        # TODO: use fitScaleBBox and adjust scrollBars accordingly
        self.fitScaleMetrics()
        self.adjustSize()
        hSB = self._scrollArea.horizontalScrollBar()
        vSB = self._scrollArea.verticalScrollBar()
        hSB.setValue((hSB.minimum() + hSB.maximum()) / 2)
        vSB.setValue((vSB.minimum() + vSB.maximum()) / 2)

    def wheelEvent(self, event):
        if event.modifiers() & Qt.ControlModifier:
            factor = pow(1.2, event.angleDelta().y() / 120.0)
            pos = event.pos()
            # compute new scrollbar position
            # http://stackoverflow.com/a/32269574/2037879
            oldScale = self._scale
            newScale = self._scale * factor
            hSB = self._scrollArea.horizontalScrollBar()
            vSB = self._scrollArea.verticalScrollBar()
            scrollBarPos = QPointF(hSB.value(), vSB.value())
            deltaToPos = (self.mapToParent(pos) - self.pos()) / oldScale
            delta = deltaToPos * (newScale - oldScale)
            # TODO: maybe put out a func that does multiply by default
            self.setScale(newScale)
            # TODO: maybe merge this in setScale
            self.adjustSize()
            self.update()
            hSB.setValue(scrollBarPos.x() + delta.x())
            vSB.setValue(scrollBarPos.y() + delta.y())
            event.accept()
        else:
            super().wheelEvent(event)

    # ------------
    # Canvas tools
    # ------------
开发者ID:bitforks,项目名称:trufont,代码行数:69,代码来源:glyphView.py

示例5: PDFAreaSelectorDlg

# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import horizontalScrollBar [as 别名]

#.........这里部分代码省略.........

        self.exitAct = QAction("E&xit", self)
        self.exitAct.setShortcut("Ctrl+Q")
        self.exitAct.triggered.connect(self.close)

        self.zoomInAct = QAction("Zoom &In (25%)", self)
        self.zoomInAct.setShortcut("Ctrl++")
        self.zoomInAct.setEnabled(False)
        self.zoomInAct.triggered.connect(self.zoomIn)

        self.zoomOutAct = QAction("Zoom &Out (25%)", self)
        self.zoomOutAct.setShortcut("Ctrl+-")
        self.zoomOutAct.setEnabled(False)
        self.zoomOutAct.triggered.connect(self.zoomOut)

        self.normalSizeAct = QAction("&Normal Size", self)
        self.normalSizeAct.setShortcut("Ctrl+S")
        self.normalSizeAct.setEnabled(False)
        self.normalSizeAct.triggered.connect(self.normalSize)

        self.fitToWindowAct = QAction("&Fit to Window", self)
        self.fitToWindowAct.setEnabled(False)
        self.fitToWindowAct.setCheckable(True)
        self.fitToWindowAct.setShortcut("Ctrl+F")
        self.fitToWindowAct.triggered.connect(self.fitToWindow)



        self.nextPageAct = QAction("&Next page", self)
        self.nextPageAct.setEnabled(True)
        self.nextPageAct.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Right))
        self.nextPageAct.triggered.connect(self.nextPage)


        self.previousPageAct = QAction("&Previous page", self)
        self.previousPageAct.setEnabled(True)
        self.previousPageAct.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Left))
        self.previousPageAct.triggered.connect(self.previousPage)



    def createMenus(self):

        self.menuBar = QMenuBar(self)

        self.fileMenu = QMenu("&File", self)
        self.fileMenu.addAction(self.exitAct)

        self.viewMenu = QMenu("&View", self)
        self.viewMenu.addAction(self.zoomInAct)
        self.viewMenu.addAction(self.zoomOutAct)
        self.viewMenu.addAction(self.normalSizeAct)
        self.viewMenu.addSeparator()
        self.viewMenu.addAction(self.fitToWindowAct)
        self.viewMenu.addSeparator()
        self.viewMenu.addAction(self.nextPageAct)
        self.viewMenu.addAction(self.previousPageAct)

        self.menuBar.addMenu(self.fileMenu)
        self.menuBar.addMenu(self.viewMenu)



    def updateActions(self):

        self.zoomInAct.setEnabled(not self.fitToWindowAct.isChecked())
        self.zoomOutAct.setEnabled(not self.fitToWindowAct.isChecked())
        self.normalSizeAct.setEnabled(not self.fitToWindowAct.isChecked())



    def scaleImage(self, factor):
        assert(self.imageLabel.pixmap())
        self.scaleFactor *= factor
        self.imageLabel.resize(self.scaleFactor * self.imageLabel.pixmap().size())

        self.adjustScrollBar(self.scrollArea.horizontalScrollBar(), factor)
        self.adjustScrollBar(self.scrollArea.verticalScrollBar(), factor)

        self.zoomInAct.setEnabled(self.scaleFactor < 3.0)
        self.zoomOutAct.setEnabled(self.scaleFactor > 0.333)


    def adjustScrollBar(self, scrollBar, factor):
        scrollBar.setValue(int(factor * scrollBar.value()
                                + ((factor - 1) * scrollBar.pageStep()/2)))



    def nextPage(self):
        if self._parent.currentPageInd < len(self._parent.pages)-1:
            self._parent.currentPageInd += 1
            self.loadImage()
            self.noPageTxt.setText(str(self._parent.currentPageInd+1))

    def previousPage(self):
        if self._parent.currentPageInd > 0:
            self._parent.currentPageInd -= 1
            self.loadImage()
            self.noPageTxt.setText(str(self._parent.currentPageInd+1))
开发者ID:christian-oreilly,项目名称:neurocurator,代码行数:104,代码来源:areaSelector.py

示例6: GlyphsCanvas

# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import horizontalScrollBar [as 别名]
class GlyphsCanvas(QWidget):
    def __init__(self, font, glyphs, pointSize=defaultPointSize, parent=None):
        super(GlyphsCanvas, self).__init__(parent)
        # XXX: make canvas font-agnostic as in defconAppkit and use
        # glyph.getParent() instead
        self.font = font
        self.fetchFontMetrics()
        self.glyphs = glyphs
        self.ptSize = pointSize
        self.calculateScale()
        self.padding = 10
        self._showKerning = False
        self._showMetrics = False
        self._verticalFlip = False
        self._lineHeight = 1.1
        self._positions = None
        self._selected = None
        self.doubleClickCallback = None
        self.pointSizeChangedCallback = None
        self.selectionChangedCallback = None

        self._wrapLines = True
        self._scrollArea = QScrollArea(self.parent())
        self._scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self._scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self._scrollArea.setWidget(self)
        self.resize(581, 400)

    def scrollArea(self):
        return self._scrollArea

    def calculateScale(self):
        scale = self.ptSize / self.upm
        if scale < 0.01:
            scale = 0.01
        self.scale = scale

    def setShowKerning(self, showKerning):
        self._showKerning = showKerning
        self.update()

    def setShowMetrics(self, showMetrics):
        self._showMetrics = showMetrics
        self.update()

    def setVerticalFlip(self, verticalFlip):
        self._verticalFlip = verticalFlip
        self.update()

    def setLineHeight(self, lineHeight):
        self._lineHeight = lineHeight
        self.update()

    def setWrapLines(self, wrapLines):
        if self._wrapLines == wrapLines:
            return
        self._wrapLines = wrapLines
        if self._wrapLines:
            sw = self._scrollArea.verticalScrollBar().width() + self._scrollArea.contentsMargins().right()
            self.resize(self.parent().parent().parent().width() - sw, self.height())
            self._scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            self._scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        else:
            sh = self._scrollArea.horizontalScrollBar().height() + self._scrollArea.contentsMargins().bottom()
            self.resize(self.width(), self.parent().parent().parent().height() - sh)
            self._scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            self._scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.update()

    def fetchFontMetrics(self):
        self.ascender = self.font.info.ascender
        if self.ascender is None:
            self.ascender = 750
        self.descender = self.font.info.descender
        if self.descender is None:
            self.descender = 250
        self.upm = self.font.info.unitsPerEm
        if self.upm is None or not self.upm > 0:
            self.upm = 1000

    def setGlyphs(self, newGlyphs):
        self.glyphs = newGlyphs
        self._selected = None
        self.update()

    def setPointSize(self, pointSize):
        self.ptSize = int(pointSize)
        self.calculateScale()
        self.update()

    def setSelected(self, selected):
        self._selected = selected
        if self._positions is not None:
            cur_len = 0
            line = -1
            for index, li in enumerate(self._positions):
                if cur_len + len(li) > self._selected:
                    pos, width = li[self._selected - cur_len]
                    line = index
                    break
#.........这里部分代码省略.........
开发者ID:n7s,项目名称:trufont,代码行数:103,代码来源:spaceCenter.py

示例7: ImageViewer

# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import horizontalScrollBar [as 别名]

#.........这里部分代码省略.........

    def createActions(self):
        self.openAct = QAction(
            QIcon(CURRENT_DIR + '/open.png'),
            "&Open...", self, shortcut="Ctrl+O",
            triggered=self.open
        )

        self.printAct = QAction(
            QIcon(CURRENT_DIR + '/print.png'),
            "&Print...", self, shortcut="Ctrl+P",
            enabled=False, triggered=self.print_
        )

        self.exitAct = QAction(
            QIcon(CURRENT_DIR + '/exit24.png'),
            "E&xit", self, shortcut="Ctrl+Q",
            triggered=self.close
        )

        self.zoomInAct = QAction(
            QIcon(CURRENT_DIR + '/zoom_in.png'),
            "Zoom &In (25%)", self, shortcut="Ctrl++",
            enabled=False, triggered=self.zoomIn
        )

        self.zoomOutAct = QAction(
            QIcon(CURRENT_DIR + '/zoom_out.png'),
            "Zoom &Out (25%)", self, shortcut="Ctrl+-",
            enabled=False, triggered=self.zoomOut
        )

        self.normalSizeAct = QAction(
            QIcon(CURRENT_DIR + '/zoom.png'),
            "&Normal Size", self, shortcut="Ctrl+S",
            enabled=False, triggered=self.normalSize
        )

        self.fitToWindowAct = QAction(
            QIcon(CURRENT_DIR + '/expand.png'),
            "&Fit to Window",
            self,
            enabled=False,
            checkable=True,
            shortcut="Ctrl+F",
            triggered=self.fitToWindow
        )

        self.aboutAct = QAction(
            QIcon(CURRENT_DIR + '/info.png'),
            "&About", self, triggered=self.about
        )

        self.aboutQtAct = QAction(
            QIcon(CURRENT_DIR + '/pyqt.png'),
            "About &Qt", self,
            triggered=QApplication.instance().aboutQt
        )

    def createMenus(self):
        self.fileMenu = QMenu("&File", self)
        self.fileMenu.addAction(self.openAct)
        self.fileMenu.addAction(self.printAct)
        self.fileMenu.addSeparator()
        self.fileMenu.addAction(self.exitAct)

        self.viewMenu = QMenu("&View", self)
        self.viewMenu.addAction(self.zoomInAct)
        self.viewMenu.addAction(self.zoomOutAct)
        self.viewMenu.addAction(self.normalSizeAct)
        self.viewMenu.addSeparator()
        self.viewMenu.addAction(self.fitToWindowAct)

        self.helpMenu = QMenu("&Help", self)
        self.helpMenu.addAction(self.aboutAct)
        self.helpMenu.addAction(self.aboutQtAct)

        self.menuBar().addMenu(self.fileMenu)
        self.menuBar().addMenu(self.viewMenu)
        self.menuBar().addMenu(self.helpMenu)

    def updateActions(self):
        self.zoomInAct.setEnabled(not self.fitToWindowAct.isChecked())
        self.zoomOutAct.setEnabled(not self.fitToWindowAct.isChecked())
        self.normalSizeAct.setEnabled(not self.fitToWindowAct.isChecked())

    def scaleImage(self, factor):
        self.scaleFactor *= factor
        self.imageLabel.resize(self.scaleFactor
                               * self.imageLabel.pixmap().size())

        self.adjustScrollBar(self.scrollArea.horizontalScrollBar(), factor)
        self.adjustScrollBar(self.scrollArea.verticalScrollBar(), factor)

        self.zoomInAct.setEnabled(self.scaleFactor < 3.0)
        self.zoomOutAct.setEnabled(self.scaleFactor > 0.333)

    def adjustScrollBar(self, scrollBar, factor):
        scrollBar.setValue(int(factor * scrollBar.value()
                                + ((factor - 1) * scrollBar.pageStep()/2)))
开发者ID:TiagoAssuncao,项目名称:encrypter_pictures,代码行数:104,代码来源:gui.py

示例8: ImageViewer

# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import horizontalScrollBar [as 别名]

#.........这里部分代码省略.........
        self.scaleImage(1.25)

    def zoomOut(self):
        self.scaleImage(0.8)

    def normalSize(self):
        self.imageLabel.adjustSize()
        self.scaleFactor = 1.0

    def fitToWindow(self):
        fitToWindow = self.fitToWindowAct.isChecked()
        self.scrollArea.setWidgetResizable(fitToWindow)
        if not fitToWindow:
            self.normalSize()

        self.updateActions()

    def about(self):
        QMessageBox.about(self, "About Image Viewer",
                "<p>The <b>Image Viewer</b> example shows how to combine "
                "QLabel and QScrollArea to display an image. QLabel is "
                "typically used for displaying text, but it can also display "
                "an image. QScrollArea provides a scrolling view around "
                "another widget. If the child widget exceeds the size of the "
                "frame, QScrollArea automatically provides scroll bars.</p>"
                "<p>The example demonstrates how QLabel's ability to scale "
                "its contents (QLabel.scaledContents), and QScrollArea's "
                "ability to automatically resize its contents "
                "(QScrollArea.widgetResizable), can be used to implement "
                "zooming and scaling features.</p>"
                "<p>In addition the example shows how to use QPainter to "
                "print an image.</p>")

    def createActions(self):
        self.openAct = QAction("&Open...", self, shortcut="Ctrl+O",
                triggered=self.open)

        self.printAct = QAction("&Print...", self, shortcut="Ctrl+P",
                enabled=False, triggered=self.print_)

        self.exitAct = QAction("E&xit", self, shortcut="Ctrl+Q",
                triggered=self.close)

        self.zoomInAct = QAction("Zoom &In (25%)", self, shortcut="Ctrl++",
                enabled=False, triggered=self.zoomIn)

        self.zoomOutAct = QAction("Zoom &Out (25%)", self, shortcut="Ctrl+-",
                enabled=False, triggered=self.zoomOut)

        self.normalSizeAct = QAction("&Normal Size", self, shortcut="Ctrl+S",
                enabled=False, triggered=self.normalSize)

        self.fitToWindowAct = QAction("&Fit to Window", self, enabled=False,
                checkable=True, shortcut="Ctrl+F", triggered=self.fitToWindow)

        self.aboutAct = QAction("&About", self, triggered=self.about)

        self.aboutQtAct = QAction("About &Qt", self,
                triggered=QApplication.instance().aboutQt)

    def createMenus(self):
        self.fileMenu = QMenu("&File", self)
        self.fileMenu.addAction(self.openAct)
        self.fileMenu.addAction(self.printAct)
        self.fileMenu.addSeparator()
        self.fileMenu.addAction(self.exitAct)

        self.viewMenu = QMenu("&View", self)
        self.viewMenu.addAction(self.zoomInAct)
        self.viewMenu.addAction(self.zoomOutAct)
        self.viewMenu.addAction(self.normalSizeAct)
        self.viewMenu.addSeparator()
        self.viewMenu.addAction(self.fitToWindowAct)

        self.helpMenu = QMenu("&Help", self)
        self.helpMenu.addAction(self.aboutAct)
        self.helpMenu.addAction(self.aboutQtAct)

        self.menuBar().addMenu(self.fileMenu)
        self.menuBar().addMenu(self.viewMenu)
        self.menuBar().addMenu(self.helpMenu)

    def updateActions(self):
        self.zoomInAct.setEnabled(not self.fitToWindowAct.isChecked())
        self.zoomOutAct.setEnabled(not self.fitToWindowAct.isChecked())
        self.normalSizeAct.setEnabled(not self.fitToWindowAct.isChecked())

    def scaleImage(self, factor):
        self.scaleFactor *= factor
        self.imageLabel.resize(self.scaleFactor * self.imageLabel.pixmap().size())

        self.adjustScrollBar(self.scrollArea.horizontalScrollBar(), factor)
        self.adjustScrollBar(self.scrollArea.verticalScrollBar(), factor)

        self.zoomInAct.setEnabled(self.scaleFactor < 3.0)
        self.zoomOutAct.setEnabled(self.scaleFactor > 0.333)

    def adjustScrollBar(self, scrollBar, factor):
        scrollBar.setValue(int(factor * scrollBar.value()
                                + ((factor - 1) * scrollBar.pageStep()/2)))
开发者ID:lmann03,项目名称:roadside-viewer,代码行数:104,代码来源:imageviewer.py


注:本文中的PyQt5.QtWidgets.QScrollArea.horizontalScrollBar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。