我正在尝试做一些我认为非常容易的事情:在没有任何布局的情况下将 QRadioButton 添加到我的 QWizardPage 中。
当用户单击 Next 按钮时,将调用以下添加 QRadioButton 的代码(信号 currentIdChanged 调用代码):
int newPositionY = 0;
for (vector<Events::VCS::PnPDevice>::const_iterator it=m_devices.begin(); it!=m_devices.end(); it++)
{
if (it->type == Events::VCS::HEADSET)
{
//add a radio button
stringstream text;
text << (it->name) << " " << (it->serialNumber);
QRadioButton* radioButton = new QRadioButton(ui.wpSINGLE_USER);
radioButton->setGeometry(50, 20 + newPositionY, 260, 40);
radioButton->setText(text.str().c_str());
newPositionY = newPositionY + 40
}
}
}
我添加了这段小代码来查看我的 QRadioButton 发生了什么
QList<QRadioButton*> listButton = ui.wpSINGLE_USER->findChildren<QRadioButton*>();
int size = listButton.size();
QRect rect1 = listButton[0]->rect();
QRect rect2 = listButton[1]->rect();
然后我意识到问题似乎是QRect。
rect1 和 rect2 的值是错误的。rect1 = (0, 0, 259, 39) 和 rect2 = (0, 0, 259, 39) rect1 的正确值应该是 (50, 20, 260, 40) 和 rect2 的正确值 (50, 60, 260, 40)
那么,问题出在哪里,如何在没有布局的情况下将 QRadioButton 添加到 QWidget 中?
编辑
这很奇怪,如果当用户单击下一步按钮时,我没有将 QRadioButton 添加到 QWizardPage 中,而是将它们添加到 QWizard 构造函数中,它可以工作。
有人能告诉我为什么我不能将 QRadioButton 添加到我的 QWizardPage 到我的插槽函数中吗?
谢谢