简体   繁体   中英

QLabel not showing in widget

I am writing a program for a psychology experiment.

The participant is shown 5 variations of an animation depicting a three object collision. Which order the animations are shown in depends on the output of a different function which determines the order (this is so that the order of the animations is different for each participant).

As the animations are very similar they are triggered by a single function which has conditionals within it to control the motion of the objects. This function is a slot which is connected to 5 buttons (each button is on a different page). When one of the buttons is pressed the appropriate animation is shown.

The issue I am having is that for the first animation, the objects show up in the window perfectly fine. BUT when I click through to the 2nd, 3rd, 4th and 5th animations, the objects don't show up on the screen at all.

Here is my code within the slot:

trialWidgets = [ui.trialWidget_1, ui.trialWidget_2, ui.trialWidget_3, ui.trialWidget_4, ui.trialWidget_5]
print('trialwidgets=', trialWidgets)

trialWidget = trialWidgets[currentTrialIndex]
print('trialwidget=',trialWidget)

preTrialTimeMs = 1000
waitTimes = int(preTrialTimeMs/msPerFrame)

A = movingObject(startingPositionAx, startingPositionAy, diameter, 'blueCircleA.png', trialWidget)
B = movingObject(startingPositionAx + (horizontalDistance * 2), startingPositionAy, diameter, 'blueCircleB.png', trialWidget)
C = movingObject(startingPositionAx + (horizontalDistance), startingPositionAy - verticleDistance, diameter, 'blueCircleC.png', trialWidget)

print('parentOfA=', A.parent())

The currentTrialIndex updates each time the slot is called which ensure that the widget the object is placed in should change each time the function is called (the currentTrialIndex is updated by reading an excel file to determine which trial the participant is in, this is done elsewhere in the file)

There are print statements in my program so I could check that the values were updating appropriately each trial... for example here is my printout when the first animation is shown (this animation shows correctly). As you'll see the number for the first object in the list of trial widgets matches the printed trial widget and the parent of A

index= 0
trialwidgets= [<PyQt5.QtWidgets.QWidget object at 0x115e37708>, 
<PyQt5.QtWidgets.QWidget object at 0x115e3d3a8>, 
<PyQt5.QtWidgets.QWidget object at 0x115e40048>, 
<PyQt5.QtWidgets.QWidget object at 0x115e42ca8>, 
<PyQt5.QtWidgets.QWidget object at 0x1176a6948>]

trialwidget= <PyQt5.QtWidgets.QWidget object at 0x115e37708>
parentOfA= <PyQt5.QtWidgets.QWidget object at 0x115e37708>

and her is my printout when the second animation should show, but doesn't. As you'll see the number for the second object in the list of trial widgets matches the printed trial widget and the parent of A, which is what I would expect and would think that my program would work given that the values seem to be correct.

index= 1
trialwidgets= [<PyQt5.QtWidgets.QWidget object at 0x115e37708>, 
<PyQt5.QtWidgets.QWidget object at 0x115e3d3a8>, 
<PyQt5.QtWidgets.QWidget object at 0x115e40048>, 
<PyQt5.QtWidgets.QWidget object at 0x115e42ca8>, 
<PyQt5.QtWidgets.QWidget object at 0x1176a6948>]
trialwidget= <PyQt5.QtWidgets.QWidget object at 0x115e3d3a8>
parentOfA= <PyQt5.QtWidgets.QWidget object at 0x115e3d3a8>

I've tried a few different things including assigning other objects directly to the 2nd-5th widgets. They show up, so I know it's nothing to do with the widget.

Why the widgets are only showing up on the first trial?

here's some code for the animation in case it's helpful. I'm not sure it's relevant though as I commented the below out and the objects still were not appearing on the screen at all

window.timerCount = 0

def moveObjects():
    window.timerCount += 1

    if currentCondition == 'incongruent':
        incHorC = incHorTouch
        incVerC = incVerTouch
    elif currentCondition == 'congruent':
        incHorC = -incHorTouch
        incVerC = incVerTouch
    elif currentCondition == 'indiscriminate':
        incHorC = 0
        incVerC = verticleDistance / noOfTimes
    elif currentCondition == 'nearIncongruent':
        incHorC = incHorN
        incVerC = incVerN
    else:
        incHorC = -incHorN
        incVerC = incVerN

    if currentSide == 'collidesA':
        incHorA = incHorTouch
        incVerA = incVerTouch
        incHorB = incHorGap - 1
        incVerB = incVerGap - 1
        bCanMove = window.timerCount > waitTimes and B.y() - incVerB > gapVerEndPoint
        aCanMove = window.timerCount > waitTimes and window.timerCount <= noOfTimes + waitTimes


    else:
        incHorB = incHorTouch
        incVerB = incVerTouch
        incHorA = incHorGap - 1
        incVerA = incVerGap - 1
        incHorC = -incHorC
        bCanMove = window.timerCount > waitTimes and window.timerCount <= noOfTimes + waitTimes
        aCanMove = window.timerCount > waitTimes and A.y() - incVerA > touchVerEndPoint

    if window.timerCount >= noOfTimes + waitTimes:
        C.setGeometry(C.x() - incHorC, C.y() - incVerC, diameter, diameter)

    if aCanMove:
        A.setGeometry(A.x() + (incHorA), A.y() - (incVerA), diameter, diameter)

    if bCanMove:
        B.setGeometry(B.x() - (incHorB), B.y() - (incVerB), diameter, diameter)

    if window.timerCount > (noOfTimes * 2) + waitTimes:
        A.hide()
        B.hide()
        C.hide()

    if window.timerCount > (noOfTimes * 2) + (waitTimes*2):
        ui.experimentWindows.setCurrentIndex(ui.experimentWindows.currentIndex()+1)
        window.animationTimer.stop()

window.animationTimer = QTimer()
window.animationTimer.timeout.connect(moveObjects)
window.animationTimer.start(msPerFrame)

I've resolved this now. I had hidden the QLabels within the animation function and forgot to reshow them afterwards.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM