2017-02-02 12 views
0

When I use delete layout_newInfo; layout_main->update() happends this. 런타임시 layout_main에서 layout_newInfo를 어떻게 제거 할 수 있습니까?Qt remove 다른 레이아웃에서 레이아웃

I need get this back after pressing button (next image)

Delete orange section (layout_newInfo) by pressing button Add Component

코드는 내가 노력 :

QLayout *layout = this->layout(); 

    QLayoutItem *item; 
    while ((item = layout->takeAt(0)) != 0) 
     layout->removeItem (item); 
    delete layout_newInfo; 
    layout_main->update(); 
+0

시도한 코드가 표시됩니다. – eyllanesc

+0

Qestien에 코드를 추가했습니다. –

+0

전달 된 item이 이미 ['QLayout :: takeAt'] (http : //)에 의해 제거 되었기 때문에'while' 루프의'layout-> removeItem (item);'호출은 아무 것도하지 않습니다. doc.qt.io/qt-5/qlayout.html#takeAt). –

답변

0

어떻게 layout_newInfo이 layout_main에 중첩되어 주어진 런타임에 layout_main에서 layout_newInfo을 제거 할 수 있습니까?

의미 적 명확한 방법 : BTW

layout_main->removeItem(layout_newInfo); // make sure layout_newInfo object deleted 
             // after either by parent or somehow else 

, 일반적으로이 같은 중첩 된 레이아웃으로 제거 할도해야합니다 그래서

delete layout_newInfo; // also removes it from upper layout 
layout_main->update(); // triggers update on the screen 

, 코드 예제의 단 2 하단 라인해야 다른 업데이트가 트리거되지 않은 경우에만 layout_main->update() 호출이 필요한 경우에 충분해야합니다.

here의 예는 QLayout에 대한 부모 인 QLayoutItem을 삭제하면 상위 레이아웃 구조에서도 제거됩니다 (소멸자가 수행함).

+0

이 부분은'layout_main = new QVBoxLayout; layout_main-> addLayout (layout_header); layout_main-> addLayout (layout_data); layout_main-> addLayout (layout_buttons); setLayout (layout_main);은 (는) 생성자입니다. 버튼을 클릭했을 때'layout_main-> addLayout (layout_newInfo); ' –

+0

'layout_newInfo'가'layout_main'에 직접 중첩되어 있다면'layout_newInfo'를 실행하고'layout_main -> update()'를 잘. – AlexanderVX

+0

그러나 일부 인공물을 작성합니다. 레이아웃이 다른 레이아웃을 가리키면 사라지지 않습니다. –

2

정확히 달성하기를 원하십니까? layout_newInfo에있는 위젯을 표시하거나 숨기려면 은 레이아웃을 사용하지 마십시오. layout_main (세로 레이아웃)에 넣은 위젯을 사용합니다.이 위젯에는 newInfo 항목과 레이아웃이 있으며, 필요한 경우 위젯에 setVisible (true/false)을 사용하십시오.

0

마지막으로 답 가장 좋은 방법은 클래스의 cpp 파일에서 void showNewInfo(QString action);

같은 무효 방법을 찾을

void MainWind::showNewInfo(QString action) 
{ 
    if(action == "true") 
    { 
     bt_search->setEnabled(false); 
     bt_production->setEnabled(false); 
     bt_drying->setEnabled(false); 
     bt_storage->setEnabled(false); 
     ln_spent->show(); 
     cb_thickness1->show(); 
     cb_thickness2->show(); 
     cb_thickness3->show(); 
     cb_EFL1->show(); 
     cb_EFL2->show(); 
     bt_newItem->show(); 
    } 
    else if(action == "false") 
    { 
     bt_search->setEnabled(true); 
     bt_production->setEnabled(true); 
     bt_drying->setEnabled(true); 
     bt_storage->setEnabled(true); 
     ln_spent->hide(); 
     cb_thickness1->hide(); 
     cb_thickness2->hide(); 
     cb_thickness3->hide(); 
     cb_EFL1->hide(); 
     cb_EFL2->hide(); 
     bt_newItem->hide(); 
    } 
} 

또한, 그것을 보여주는 단편의 setText (""), 그래서 다음 번에 사용할 수있다 명확 할 것이다;