Сам справился! (: Получилось вроде все как хотел. Ниже код класса и исходники готовые:
| Код |
/* Список окон QMdiArea в выпадающем списке QComboBox. В качестве родителя необходимо указать QMdiArea.
Пример использования: WindowList *newList=new WindowList(ui->mdiArea); ui->mainToolBar->addWidget(newList);
Примечание! Все дочерние окна QMdiArea должны иметь аттрибут: setAttribute(Qt::WA_DeleteOnClose,true);
В противном случае окна не будут удаляться после закрытия, а будут просто скрываться, так же они останутся в списке окон и при выборе окно будет снова показано. */
class WindowList:public QComboBox{ Q_OBJECT public: QMdiArea *mParent; WindowList(QWidget *parent=0):QComboBox(parent){ mParent=static_cast<QMdiArea*>(parent); this->setMinimumSize(250,NULL); connect(this,SIGNAL(activated(int)),this,SLOT(itemActivation(int))); connect(mParent,SIGNAL(subWindowActivated(QMdiSubWindow*)),this,SLOT(itemListRefresh(QMdiSubWindow*))); itemListRefresh(NULL); }
public slots: void itemActivation(int index){ if(index>-1){ mParent->setActiveSubWindow(mParent->subWindowList().at(index)); mParent->subWindowList().at(index)->show(); } }
int searchSubWindowIndex(QMdiSubWindow* subWindow){ int r=-1; if(mParent->subWindowList().size()>0){ for(int i=0;i<mParent->subWindowList().size();++i){ if(mParent->subWindowList().at(i)==subWindow) { r=i; } } } return®; }
void itemListRefresh(QMdiSubWindow* subWindow){ this->clear(); if(mParent->subWindowList().count()>0){ setEnabled(true); for(int i=0;i<mParent->subWindowList().count();++i) { addItem(mParent->subWindowList().at(i)->windowTitle()); } this->setCurrentIndex(searchSubWindowIndex(subWindow)); } else { setEnabled(false); addItem("[Нет открытых окон]"); }
} }; /* ------------------------------------------------ */
|
|