Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Activate scroll bar?



  • How I can activate this scroll bar with Qt Designer?

    11563a05-1845-4b12-8fa8-f18409c6a95b-image.png


  • Banned

    What do you mean by "activate" as it appears to have been activated? And why use the Designer are you needing the XML Code it produces?


  • Banned

    Okay in case you did something wrong in your code here is a Python-Qt version of kind of what you are showing where the QScrollArea works as it is meant too.

    from PyQt5.QtCore    import *
    from PyQt5.QtGui     import *
    from PyQt5.QtWidgets import *
    
    class LeftAlignButton(QWidget):
        def __init__(self, parent, id, text):
            QWidget.__init__(self)
            self.Parent = parent
            self.btnId  = id
            
            self.btnLftAlgn = QPushButton(text)
            self.btnLftAlgn.clicked.connect(self.Pushed)
            
            HBox = QHBoxLayout()
            HBox.addWidget(self.btnLftAlgn)
            HBox.addStretch(1)
            
            self.setLayout(HBox)
            
        def Pushed(self):
            self.Parent.Pushed(self.btnId)
    
    class VerticalButtons(QWidget):
        def __init__(self, parent, ButCnt):
            QWidget.__init__(self)
            self.Parent  = parent
            self.MaxBtns = ButCnt
            self.Butns   = {}
    
            VBox = QVBoxLayout()
            VBox.addStretch(1)
            for Id in range(1,self.MaxBtns+1):
                Text = 'Push ' + str(Id)
                self.Butns[Id] = LeftAlignButton(self, Id, Text)
                VBox.addWidget(self.Butns[Id])
            VBox.addStretch(1)
    
            self.setLayout(VBox)
    
        def Pushed(self, BtnId):
            self.Parent.Pushed(BtnId)
    
    class MainWindow(QWidget):
        def __init__(self):
            QWidget.__init__(self)
    
            Top=300; Left=700; Width=100; Hight=100
            self.setGeometry(Left, Top, Width, Hight)
            self.setWindowTitle('Scrolling')
    
            self.FourVButs = VerticalButtons(self, 4)
            
            self.ScrlArea = QScrollArea()
            self.ScrlArea.setWidget(self.FourVButs)
    
            HBox = QHBoxLayout()
            HBox.addWidget(self.ScrlArea)
    
            self.setLayout(HBox)
    
        def Pushed(self, BtnId):
            print('Button (',BtnId,') was pushed')
    
    
    if __name__ == '__main__':
        MainThred = QApplication([])
    
        MainGui = MainWindow()
        MainGui.show()
    
        MainThred.exec()
    


  • i'm want to know if is possible to activate the scroll bar of lineScroll with the QtDesigner (without input the Qt code in the scope)..

    About this configs:

    1954615e-1686-4584-8c14-2855a2c8b104-image.png


  • Banned

    Sorry I cannot help you with the Designer because to me unless you absolutely need that XML code it generates (which I do not) you are just shooting yourself in the foot by using it due to major amount of extra complexity it adds to your program (aka headaches). Further I just teach using the basic python-qt as it was meant to be used which does not use the XML code. Now there are others on here, I think, that use the Designer perhaps one of them might chime in on this -- again sorry.

    However I will say the above can easily be reproduced using straight Python-Qt and I could probably whip that up in about as much time (or less) as you would putting it together from scratch using the Designer.

    Also if I were to take a guess from the way it looks the actual Scroll Area is covering that entire display rather than just those 2 Scroll Areas like perhaps it suggests it does

    And again it is unclear by what you mean by "activate" the scroll bar -- the scroll bar of a Scroll Area is auto-activated based on the contents you put within the Scroll Area and the size of the Display Area it is placed within



  • @Julie-Db
    I could (well!) be wrong, but try unchecking that widgetResizable? I don't know for sure whether scroll bars activate to allow scrolling at design-time in the Designer. Also, I can't see/tell what widget you have picked to be the QScrollArea's widget? If you have that wrong, it may well affect ability to display/scroll.


  • Banned

    Ah so that is not the window you wish to create but a picture of the Qt Designer interface -- you might have wanted to point that out btw ;) not everyone here plays with those toys



  • I believe you are missing a layout for the widget living inside the QScrollArea. So far there is no reason for the widget inside the scroll area to be larger than the scroll area itself. If you put the buttons into the layout of the widget inside the scroll area, the widget will resize accordingly and trigger the use of scrollbars when necessary.



  • @SimonSchroeder
    Which is what I tried to suggest to the OP via

    Also, I can't see/tell what widget you have picked to be the QScrollArea's widget? If you have that wrong, it may well affect ability to display/scroll.


  • Banned

    Just another case in point of why one ought not use the Designer it is a bigger headache upfront and down the road as after they resolve this issue they are just going to collide with another and another and another --- I just do not understand why folks feel its easier to use when it definitely is not easier to use when you step back and look at the bigger picture. I do admit it seems "sexier" so-to-speak because of that drag-n-drop functionality but definitely not easier from a coding perspective


Log in to reply