से सभी बच्चों को हटाएं मेरे पास scrollArea के अंदर QVBoxLayout है। मैं गतिशील रूप से QFormLayout एस जोड़ता हूं।QVBoxLayout
widgetTreeStruct* tree = new widgetTreeStruct(QString::number(numberOfGraphs));
QFormLayout* layout = tree->getTree(); // get QFormLayout
ui->verticalLayout_2->addLayout(layout); //add to the vertical layout
एक बिंदु पर मैं QVBoxLayout से सभी जोड़ा QFormLayouts दूर करने के लिए की जरूरत है।
मैंने ऐसा करने के कई तरीकों की कोशिश की।
- qDeleteAll का उपयोग करना()
qDeleteAll(ui->verticalLayout_2->children());
2.delete आइटम एक के बाद एक
QLayoutItem* child;
while((child = ui->verticalLayout_2->takeAt(0)) != 0)
{
if(child->widget() != 0)
{
delete child->widget();
}
delete child;
}
द्वारा लेकिन कुछ नहीं हुआ। केवल एक चीज है जब मैं QVBoxLayout में आइटम जोड़ने का प्रयास करता हूं, फिर से पहले जोड़े गए आइटमों के शीर्ष पर नए आइटम जोड़े जाते हैं।
मैं समझ रहा, पुनः बनाने फिर से रंगना, अद्यतन, ताज़ा या कुछ और करना है। मैंने ui->verticalLayout_2->update();
की कोशिश की लेकिन मेरे लिए काम नहीं किया।
तो, मुझे क्या करना चाहिए?
यह वास्तव में, * * करने का सही तरीका है। +1 –