Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Scrollarea scroll not set
Qt 6.11 is out! See what's new in the release blog

Scrollarea scroll not set

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.6k Views 2 Watching
  • 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 Offline
    P Offline
    prem1980
    wrote on last edited by prem1980
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

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

        P Offline
        P Offline
        prem1980
        wrote on last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • P prem1980

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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
          0
          • mrjjM mrjj

            @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 Offline
            P Offline
            prem1980
            wrote on last edited by
            #5

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

            mrjjM 1 Reply Last reply
            0
            • P prem1980

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              P 1 Reply Last reply
              0
              • mrjjM mrjj

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

                P Offline
                P Offline
                prem1980
                wrote on last edited by prem1980
                #7

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

                mrjjM 1 Reply Last reply
                0
                • P prem1980

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved