擅长:python、mysql、java
<p>你混淆了多个问题:</p>
<ol>
<li><p>您不应该在paint事件中添加新的小部件。按钮应该添加到构造函数中的示例中。</p></li>
<li><p>你应该从qpushbutton开始,让它们工作,然后再切换到自己的类。10x10太小,无法显示按钮!</p></li>
<li><p>小部件不应该显示自己。它的用户应该这么做。</p></li>
<li><p>按钮没有视口。</p></li>
<li><p>添加到已显示的小部件中的小部件将不可见。</p></li>
</ol>
<p>从这样开始:</p>
<pre><code>class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
theta = 2 * np.pi / 15
for i in range(15):
angle = theta * (i + 1)
dx = int(round(self.width()/2 + self.width()/3 * np.cos(angle)))
dy = int(round(self.height()/2 + self.height()/3 * np.sin(angle)))
b = QPushButton("test", parent = self)
b.setGeometry(QRect(dx, dy, 50, 50))
app = QApplication(sys.argv)
ex = Example()
ex.setGeometry(300, 300, 350, 100)
ex.show()
sys.exit(app.exec_())
</code></pre>