简体   繁体   English

QLabel没有显示在小部件中

[英]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. 向参与者显示了描绘三个对象碰撞的5种动画变体。 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). 此功能是一个插槽,连接到5个按钮(每个按钮在不同的页面上)。 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) 每次调用插槽时currentTrialIndex都会更新,以确保每次调用函数时都会更改放置对象的窗口小部件(通过读取excel文件来确定参与者所处的试用版来更新currentTrialIndex,这是在其他地方完成的在文件中)

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 如您所见,试用窗口小部件列表中第一个对象的编号与打印的试用窗口小部件和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. 如您所见,试用版窗口小部件列表中第二个对象的编号与打印的试用版窗口小部件和A的父代相匹配,这是我所期望的,并且鉴于值似乎正确,我认为我的程序可以运行。

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. 我尝试了一些不同的操作,包括将其他对象直接分配给第2-5个窗口小部件。 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. 我已经将QLabels隐藏在动画功能中,但是忘记了以后再显示它们。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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