0

I have created an interface for running inside another program using pyqt5. for this I use the code that I put at the end of the post. in any case, as it can be seen there are several lines of the gridLayout that are created over a loop (for i in range(0,7):), the issue comes from this, the number of lines in this section (in the example 7), it is dependant of external variables and can be equal to a N numbers. when N is too big the created window is bigger than the screen and I can no change the option for the not visible lines, nor acept/cancel the window. I am seeking help in trying to solve this issue, I was looking to add an scroable section (for the lines of the for loop) of a 4 or 5 height of lines (of the gridLayout) and that has an scroable bar that I can go down with it to see the different lines of created within the loop. but i could not make it work nor find a correct tutorial that explains this. I also add a screenshot of what i have now and a mockup of what I am looking to do: enter image description here

def fun_1():
    print('a')
def fun_2():
    print('a')
def fun_3():
    print('a')

from PyQt5.QtWidgets import QWidget, QMessageBox
from PyQt5 import QtCore, QtGui
import PyQt5.QtCore as QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt

dialog = QDialog()
dialog.resize(550,50)
dialog.setWindowTitle("Input size")
layout = QGridLayout(dialog)

counter=0

checkBox=QCheckBox('checkBox')
checkBox.setChecked(1)
layout.addWidget(checkBox,counter,0,1,5)
checkBox.stateChanged.connect(fun_1)

label_ratio=QLabel('<b>Label 1:</b>')
layout.addWidget(label_ratio,counter,4,1,1)
label_ratio.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

inputsLines_1=[[] for i in range(0,8)]

inputsLines_1[-1]=QLineEdit("value")
layout.addWidget(inputsLines_1[-1],counter,5,1,4)
counter=counter+1

sepBar_1=QLabel("<b>======================================================================================================================</b>")
layout.addWidget(sepBar_1,counter,0,1,8)
counter=counter+1

title=QLabel("<b>Group i</b>: [min, max]<b>*</b>")
layout.addWidget(title,counter,1,1,1)
aclaration3=QLabel("<b>Show/Hide</b>")
layout.addWidget(aclaration3,counter,7,1,1)
counter=counter+1

sepBar_2=QLabel("<b>===================================================== [Group] =====================================================</b>")
layout.addWidget(sepBar_2,counter,0,1,8)
counter=counter+1

combobox=[[] for i in range(0,7)]
comboboxCurrentItem=[[] for i in range(0,7)]

label_1=[[] for i in range(0,7)]
label_1CurrentItem=[[] for i in range(0,7)]

inputsLines_1=[[] for i in range(0,7)]
inputsLines_1CurrentItem=[[] for i in range(0,7)]

label_2=[[] for i in range(0,7)]
label_2CurrentItem=[[] for i in range(0,7)]

inputsLines_2=[[] for i in range(0,7)]
inputsLines_2CurrentItem=[[] for i in range(0,7)]

checkBoxShowHide=[[] for i in range(0,7)]
option=  ['option 1']
for i in range(0,7):
        w = QLabel(" ")
        w.setStyleSheet("background:rgb("+str(i)+");")
        layout.addWidget(w,counter,0,1,1)
        
        groupLabel=QLabel("<b>Group "+str(i)+"</b>")
        layout.addWidget(groupLabel,counter,1,1,1)
        
        combobox[i]=QComboBox()
        combobox[i].addItems(option)
        combobox[i].setCurrentText(option[0])
        comboboxCurrentItem[i]=combobox[i].currentText()
        combobox[i].currentTextChanged.connect(fun_2)
        layout.addWidget(combobox[i],counter,2,1,1)
        
        label_1[i]=QLabel('a:')
        label_1CurrentItem[i]=label_1[i].text()
        layout.addWidget(label_1[i],counter,3,1,1)
        
        inputsLines_1[i]=QLineEdit("0")
        inputsLines_1CurrentItem[i]=inputsLines_1[i].text()
        layout.addWidget(inputsLines_1[i],counter,4,1,1)
        
        label_2[i]=QLabel('b:')
        label_2CurrentItem[i]=label_2[i].text()
        layout.addWidget(label_2[i],counter,5,1,1)
        
        inputsLines_2[i]=QLineEdit(str(1))
        inputsLines_2CurrentItem[i]=inputsLines_2[i].text()
        layout.addWidget(inputsLines_2[i],counter,6,1,1)
        
        checkBoxShowHide[i]=QCheckBox("")
        checkBoxShowHide[i].setChecked(1)
        layout.addWidget(checkBoxShowHide[i],counter,7,1,1)
        checkBoxShowHide[i].setLayoutDirection(Qt.RightToLeft)
        checkBoxShowHide[i].stateChanged.connect(fun_3)
        counter=counter+1

aclaration=QLabel("<b>*:</b> aclaration")
layout.addWidget(aclaration,counter,0,1,4)
aclaration.setWordWrap(True)
counter=counter+1

sepBar_3=QLabel("<b>======================================================================================================================</b>")
layout.addWidget(sepBar_3,counter,0,1,8)
counter=counter+1

okbox = QDialogButtonBox(dialog)
okbox.setOrientation(QtCore.Qt.Horizontal)
okbox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
layout.addWidget(okbox,counter,4,1,4)

dialog.show()

I tried to add QScrollArea() without succes

9
  • You should use the scroll area for the whole section, not just part of it. Please show us your attempts in using it. Feb 7 at 18:32
  • I have not succesfully used QScrollArea(), i could not find any tutorial where this is shown for pyqt5 and sincerently I am a little bit lost, in any form that I search over internet to find a tutorial/guide on how to use QscrollArea() outside of this one link which did not help me to understand how this works.
    – otaolafr
    Feb 7 at 18:49
  • That tutorial is quite straightforward and the usage of QScrollArea is simple: you create a container widget, set a layout for it, add the child widgets to the layout, and set that container widget for the scroll area. Don't try to directly apply that tutorial to your code. Start by using the code in their examples in order to understand how it works, then do simple experiments changing some aspects (type of added widgets, etc.), and finally try to apply it to your needs. Feb 7 at 18:54
  • my issue is that the tutorial, if I literally copy/paste it. it closes the program where I need to run the script. (as I mentionned in my first post, I need to run it from a python container inside a program, 'salome-platform', and when I run the script it closes the program directly, I imagine that it is because it is pyqt5 based too and it close itself?, i dont know)
    – otaolafr
    Feb 7 at 18:59
  • 1
    You don't seem to understand. You have to first learn how to use QScrollArea and the concepts behind it, and you do that by properly following that tutorial, running it standalone. THEN, when you'll have understood how QScrollArea works, you will apply the concept you've learnt to your code. You must learn how something works before using it as you want, you cannot hope to just copy and paste code without even understanding what it does. Programming is not a matter of taking some code and randomly putting it together: you have to understand what it does, and know what you're doing. Feb 7 at 19:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.