PyQt4 如何找到 QGridLayout 中小部件的行号?
我有一个 PyQt4 应用程序,其中 QGridLayout 作为布局。此布局中有 n 个小部件,每个小部件位于另一行,但不位于另一列。我已经使用构造函数制作了所有小部件。我想知道,如何获取网格布局中小部件的行号,以便当我单击它时,它会获取该数字,并且我可以在代码中进一步使用它。
代码如下所示:
...
class sampleWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
...
self.show()
....
class mainClass(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)
for i in xrange(10):
widget = sampleWidget()
widget.setObjectName("samplewidget" + i)
layout.addWidget(i, 0)
self.show()
....
我已经进行了所有必要的导入以及运行程序所需的所有内容,不用担心。我唯一担心的是如何获取创建的小部件的行号。
如果有人愿意帮助我,我将非常感激!
祝你有美好的一天。
I have a PyQt4 application with a QGridLayout as Layout. This layout has n widgets in it, each on another row, but not on another column. I have made all the widgets using a constructor. I was wondering, how do I get the row number of a widget in the grid layout, so that when I click on it, it gets that number and I can use it further in my code.
The code looks like this:
...
class sampleWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
...
self.show()
....
class mainClass(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)
for i in xrange(10):
widget = sampleWidget()
widget.setObjectName("samplewidget" + i)
layout.addWidget(i, 0)
self.show()
....
I have made all the necessary imports and all what is needed to run the program, don't worry. My only worry is how to get the row number of a widget created.
If someone is willing to help me I would be very grateful!
Have a great day.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能会遗漏一些明显的东西,但这至少是做到这一点的一种方法。
编辑:我对我的第一个建议并不满意。因此改变了它。对于这个问题可能有点过分,但应该展示如何获取您所要求的信息。
I might be missing something obvious but this is at least one way of doing it.
Edit: I wasn't happy with my first suggestion. Changed it therefore. Might be a bit overboard in regards to the question but should show how to get the information you asked for.