c++ - How to get direct access to a QWidget which is an item of a QToolBox? - Stack Overflow

admin2025-04-27  4

I have a QToolBox which has a page, which has a QWidget and the QWidget has a QLabel. How can I access the QLabel only with direct access to the QToolBox?

QToolBox* toolBox = new QToolBox;

void insert()
{
    QWidget *newWidget = new QWidget;
    toolBox->insertItem(newWidget, toolBox->count(), "some text");
    QLabel *newLabel = new QLabel;
    newLabel->setParent(newWidget);
    newLabel->setGeometry(10, 10, 49, 16);
}

I thought I can do toolBox->widget(index)->children().at(0) but the function children() returns the wrong type (I would need QLabel and not QWidget).

转载请注明原文地址:http://anycun.com/QandA/1745707423a91105.html