Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved Scrollarea scroll not set

    General and Desktop
    3
    8
    688
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      prem1980 last edited by prem1980

      Im using pyqt4 to create a scrollarea.

      When I load the image I dont see the scrollbar being set.

      import sys
      from PyQt4 import QtGui, QtCore, Qt
      
      class Canvas(QtGui.QWidget):
          def __init__(self, *args, **kwargs):
              super(Canvas, self).__init__()
              self.pixmap = QtGui.QPixmap()
      
          def paintEvent(self, event):
              print 'paintevent'
              painter = QtGui.QPainter(self)
      #         painter.scale(3,3)
      #         painter.translate(200, 200)
              painter.drawPixmap(QtCore.QPoint(), self.pixmap)
      
      class Window(QtGui.QMainWindow):
      
          def __init__(self):
              super(Window, self).__init__()
              self.setGeometry(50, 50, 500, 300)
              self.setWindowTitle("PyQT tuts!")
              self.setWindowIcon(QtGui.QIcon('pythonlogo.png'))
              openFile = QtGui.QAction("Open File", self)
              openFile.setShortcut("Ctrl+O")
              openFile.setStatusTip('Open File')
              openFile.triggered.connect(self.file_open)
              zoomIn = QtGui.QAction("Zoom", self)
              zoomIn.setShortcut("Ctrl+z")
              zoomIn.setStatusTip('Open File')
              zoomIn.triggered.connect(self.zoom_in)
              self.scrollArea = QtGui.QScrollArea()
      #         self.scrollBars = {
      #             QtCore.Qt.Vertical: self.scrollArea.verticalScrollBar(),
      #             QtCore.Qt.Horizontal: self.scrollArea.horizontalScrollBar(),
      #         }
              self.statusBar()
              mainMenu = self.menuBar()
      
              fileMenu = mainMenu.addMenu('&File')
              fileMenu.addAction(openFile)
              fileMenu.addAction(zoomIn)
              
              self.canvas = Canvas()
      #         self.scrollArea.setWidget(self.canvas)
      #         self.scrollArea.setWidgetResizable(True)
      #         self.scrollArea.setFixedHeight(400)
              self.home()
      #         self.resize(200, 200)
      
          def home(self):
              self.show()
      
          def file_open(self):
              name = QtGui.QFileDialog.getOpenFileName(self, 'Open File')
              if name:
                  self.load_pixmap(QtGui.QPixmap(name))
      
          def load_pixmap(self, pixmap):
              self.canvas.pixmap = pixmap
              self.scrollArea.setWidget(self.canvas)
              self.scrollArea.setWidgetResizable(True)
              self.setCentralWidget(self.scrollArea)
      #         self.canvas.adjustSize()
      #         self.canvas.update()
      
          def zoom_in(self):
              print 'zoom in'
              
              print self.scrollArea
              print self.scrollBars[QtCore.Qt.Horizontal].value()
              self.scrollBars[QtCore.Qt.Horizontal].setValue(10)
              print self.scrollBars[QtCore.Qt.Horizontal].value()
              print self.scrollArea.horizontalScrollBarPolicy()
      
      def run():
          app = QtGui.QApplication(sys.argv)
          GUI = Window()
          sys.exit(app.exec_())
      
      run()
      
      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        Please take a look at the Image Viewer example to see how you can use a QScrollArea properly.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        P 1 Reply Last reply Reply Quote 1
        • P
          prem1980 @SGaist last edited by

          @SGaist Thanks, its not working once I load the image. Also, im not very familiar with C++

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @prem1980 last edited by

            @prem1980

            Hi, you mean Image viewer is not working when you load and image ?
            Try to make window smaller. Picture has to be bigger than window before scrollbars will come.

            P 1 Reply Last reply Reply Quote 0
            • P
              prem1980 @mrjj last edited by

              @mrjj The widget containing the pixmap is loading properly but the scroll bar is not visible.

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @prem1980 last edited by

                @prem1980
                Hi
                Even if u make window really small ?
                alt text

                P 1 Reply Last reply Reply Quote 0
                • P
                  prem1980 @mrjj last edited by prem1980

                  @mrjj thats correct..Did you use the python code that was given?

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @prem1980 last edited by

                    @prem1980
                    Hi
                    Hmm are we talking the Image sample or the your code here ?
                    Image sample works fine for me so i wonder why you said it did not for you.
                    Anyway, its set up this way

                    imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
                    imageLabel->setScaledContents(true);    
                    scrollArea->setWidget(imageLabel);
                    

                    sorry cant type it in python.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post