following is my problem statement:

create a horizantal layout in display
add stackedwidget to this Hlayout
the stackedwidget contains imagesWidget and loadWidget
the imagesWidget is further divided into gridlayout which contains some icons
so on the stackedwidget i have a plain widget and a widget withe gridlayout

now , when i click on any icon of the gridlayout it should open loadwidget and on to that
my application should be visible(here i am just playing with colors instead of applications)
for this purpose i again divide grid layout into Horizantal layout and adding the apps widget.

i face two problems here:

1) my gridlayout icons on imagesWidget are coming properly but when i select them i can see
under those icons same icons are present( i dont understand how i got duplicate)

2) when i close my application i am following the steps mentioned in exitapp code:

but my background of the loadWidget is still retianed but with icons from imageWidget

unfortunately i cannot paste the connect calls because the loading is not handled by connect
but some external events from some other module.

below is list of steps i am following.


------------------------------------------
Qt Code:
  1. controlsLayout=new QHBoxLayout();
  2. display->setLayout(controlsLayout);
  3.  
  4. imagesWidget = new QWidget;
  5. loadWidget = new QWidget;
  6.  
  7. QGridLayout *imagesLayout=new QGridLayout();
  8.  
  9. controlsLayout=new QHBoxLayout();
  10. display->setLayout(controlsLayout);
  11.  
  12. imagesWidget = new QWidget;
  13. loadWidget = new QWidget;
  14.  
  15. imagesWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
  16. imagesWidget->setLayout(imagesLayout);// setting a grid layout for imagesWidget
  17. imgstack = new QStackedWidget; // new stacked widget for imagesWidget and loadwidget
  18. imgstack->addWidget(imagesWidget);
  19. imgstack->addWidget(loadWidget);
  20. qDebug("imgstack cnt = %d",imgstack->count());
  21.  
  22. controlsLayout->addWidget(imgstack); // stacked widget to horizantal layout of of display
  23.  
  24. appstack = new QStackedWidget; // new stacked widget for applications
  25. const char *colors[]={"background-color: white",
  26. "background-color: black",
  27. "background-color: blue",
  28. "background-color: green",
  29. "background-color: yellow",
  30. "background-color: red",
  31. "background-color: pink",
  32. "background-color: cyan",
  33. "background-color: white"
  34. }; // unique colors are given for each widget to identify
  35.  
  36.  
  37. for(int apno = 0;apno < 9;apno ++){
  38. appwidgs[apno] = new QWidget;
  39. appwidgs[apno]->setStyleSheet(colors[apno]);
  40. appstack->addWidget(appwidgs[apno]);
  41. }
To copy to clipboard, switch view to plain text mode 

--------------------------
upon click on any of the image the following will be performed.

Qt Code:
  1. imgstack->setCurrentIndex(1);
  2. //loadWidget->setStyleSheet("background-color: blue");
  3. qDebug("currindx=%d\n",imgstack->currentIndex());
  4.  
  5. loadapp();
To copy to clipboard, switch view to plain text mode 
--------------------------
loadapp code:

Qt Code:
  1. loadWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
  2. loadWidget->setLayout(hl);
  3. hl->addWidget(appstack,0,0);
  4.  
  5. qDebug("curr_apps =%d",appstack->currentIndex());
  6. appstack->setCurrentIndex(currpos);
To copy to clipboard, switch view to plain text mode 
---------------------------------------

exitapp code:

Qt Code:
  1. appstack->removeWidget(appwidgs[currpos]);
  2. imgstack->removeWidget(loadWidget);
  3. imgstack->setCurrentWidget(imagesWidget);
To copy to clipboard, switch view to plain text mode