How can I change TabView's tab programatically? For example user have 2'nd tab opened and I want to change tab to the first one.
In C++ you have to do it as following:
int index = 1;
if (tabcontrol->TabItems->Size > index)
{
tabcontrol->SelectedIndex = index;
}
According to this note
You can do it by the following:
// Only select the tab if it is in the list
if (tabToSelect < TabRoot.TabItems.Count)
{
TabRoot.SelectedIndex = tabToSelect;
}
Related
I have a CTabView and add a tab like AddView(RUNTIME_CLASS(CMyView1), _T("View1"));. But how do I get a pointer to the created CMyView1 class created in the tab?
TIA!!
You can do something like this:
CMFCTabCtrl& MFCTabCtrl = YourTabView.GetTabControl();
for(int i = 0;i < MFCTabCtrl.GetTabsNum();++i)
{
CMyView1* pView = (CMyView1*)MFCTabCtrl.GetTabWnd(i);
....
}
Try to look at the MFC-MDI tab view Implementation, when you are talking about views, this is the easiest way.
I have some problems with QTabWidget. In case of the missing Hide functionality I have to build my own. According to the documentation I use removeTab and insertTab, but with insert Tab I have a problem to show the Tab page that is removed.
I use to add
RibbonTabContent *ribbonTabContent = new RibbonTabContent;
QTabWidget::addTab(ribbonTabContent, tabIcon, tabName);
To remove is use:
void Ribbon::hideTab(const QString &tabName)
{
// Find ribbon tab
for (int i = 0; i < count(); i++)
{
if (tabText(i).toLower() == tabName.toLower())
{
QTabWidget::removeTab(i);
break;
}
}
}
Both functions are working, pWidget is always null. But now the insert function do not work well. I think there I have a problem, but do not understand my problem.
void Ribbon::showTab(const QString &tabName){
// Find ribbon tab
QWidget* pWidget= QTabWidget::findChild<RibbonTabContent *>(tabName);
if(pWidget){
QTabWidget::insertTab(2,pWidget, tabName);
}
}
Maybe someone can help me out?
If you call QTabWidget::removeTab you remove the tab at the specified index from the children tree of your QTabWidget, the tab instance is not actually deleted though, so when you search for that same tab with QTabWidget::findChild you can't find it because it's not a child of your QTabWidget anymore. From the code you show I think you probably would not find it anyway since findChild searches for a widget with the specified objectName but you never set it for your tab.
A solution would be to store the removed tabs and then restore them when you please.
Assuming m_hiddenTabs is a QHash<QString, QWidget*> or QMap<QString, QWidget*> you could try something like this.
void Ribbon::hideTab(const QString &tabName)
{
// Find ribbon tab
for (int i = 0; i < count(); i++)
{
if (tabText(i).toLower() == tabName.toLower())
{
m_hiddenTabs.insert(tabName.toLower(), QTabWidget::widget(i));
QTabWidget::removeTab(i);
break;
}
}
}
void Ribbon::showTab(const QString &tabName){
// Find ribbon tab
auto tab = m_hiddenTabs.take(tabName.toLower());
if(tab){
QTabWidget::insertTab(2, tab, tabName);
}
}
Since Qt 5.15 it is also possible to use setTabVisible:
void QTabWidget::setTabVisible(int index, bool visible)
If visible is true, the page at position index is visible; otherwise the page at position index is hidden. The page's tab is redrawn appropriately.If visible is true, the page at position index is visible; otherwise the page at position index is hidden. The page's tab is redrawn appropriately.
It is unfortunate that QTabBar is unable to 'hide' a tab.
Here is my very easy work-around: mark the tabs 'disabled' instead (e.g. ui->tabWidget->setTabEnabled(tabIndex, false);).
Then, use stylesheets to style the "disabled" tab as entirely invisible and taking up no space:
QTabBar::tab:disabled
{
min-width: 0px;
max-width: 0px;
color: rgba(0,0,0,0);
background-color: rgba(0,0,0,0);
}
This works near-perfectly for me, with the only downside being that you can't have both disabled and "hidden" tabs in the same tabbar. However, usually I want one or the other, not both in the same bar.
VS2010 with an MDI document layout using tabs along the top to switch between documents. Each document is a "live" view into a database, where the persistent data per document is a group of configuration settings.
We would like to allow the user to rearrange the tabs (this functionality is built in), but need to persist this new order. Right now it appears the document z-order is not affected by moving the tabs around. when closing the app, the documents close in the order they were opened so this is not helpful in determining the final tab order on close.
We are using the EnableMDITabbedGroups(TRUE, mdiTabParams) with m_bEnableTabSwap = TRUE which is the default.
Thanks! Ended up with the following solution in the MainFrame::OnClose() method.
Note that this code example uses two custom classes of 1) CSpectraAnalysisUtilityView which inherits from CView and 2) CReviewDataFolder which is our object that we needed to update the recent Tab Order.
This code solution also implements the GetMDITabGroups in case there are multiple group windows open.
void CMainFrame::OnClose()
{
iReviewDataFolderOrder = 1;
const CObList& tabGroups =m_wndClientArea.GetMDITabGroups();
if (0 < tabGroups.GetCount())
{
POSITION pos = tabGroups.GetHeadPosition();
CMFCTabCtrl* pCrtTabCtrl;
while(pos != NULL)
{
pCrtTabCtrl=DYNAMIC_DOWNCAST(CMFCTabCtrl, tabGroups.GetNext(pos));
int count = pCrtTabCtrl->GetTabsNum();
for(int i = 0; i < count; i++)
{
CWnd* pWnd = pCrtTabCtrl->GetTabWndNoWrapper(i);
CMDIChildWnd *pChild = ((CMDIChildWnd*)(pWnd));
if (pChild)
{
CView *pView = pChild->GetActiveView();
if (pView)
{
if (pView->IsKindOf(RUNTIME_CLASS(CSpectraAnalysisUtilityView)))
{
CSpectraAnalysisUtilityView* specUtilView;
specUtilView = (CSpectraAnalysisUtilityView*)pView;
CReviewDataFolder* pDataFolder = specUtilView->GetSpecReviewDataFolder();
if(pDataFolder)
{
pDataFolder->SetRecentOrder(iReviewDataFolderOrder);
iReviewDataFolderOrder++;
}
}
}
}
}
}
}
CMDIFrameWnd::OnClose();
}
Upon destruction of the outer main frame (OnDestroy) you can access the the CMFCTabCtrl members and can loop over each tab and determine the current sequence stored in the tab. GetTabWnd will allow you to access each tab by its index.
To access the tab control use CMDIClientAreaWnd::GetMDITab.
I have combo box and delete button. I want to make next combo box item pop-up when delete button pressed and when last item deleted clean combo box selected item.
I tried several methods with indexes but even one wont help me.
there is my code:
if(IDYES == MessageBox(L"Delete save?",L"Delete", MB_YESNO|MB_ICONQUESTION)){
CString pFileName = L"Save\\"+str+".dat";
CFile::Remove(pFileName);
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_SAVE);
pComboBox->ResetContent();
}
How I can to make next combo box item pop-up when delete button pressed and when last item deleted clean combo box selected item?
I found a solution:
void CL2HamsterDlg::OnBnClickedButtonDelete(){
if(Validate()){
if(IDYES == MessageBox(L"Delete save?",L"Delete", MB_YESNO|MB_ICONQUESTION)){
CString pFileName = L"Save\\"+str+".dat";
CFile::Remove(pFileName);
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_SAVE);
lookforfile();
int nIndex = pComboBox->GetCurSel();
if (nIndex == CB_ERR)
pComboBox->SetCurSel(0);
else{
pComboBox->SetEditSel(0, -1);
pComboBox->Clear();
}
}
LoadSave(false);
}else
AfxMessageBox(L"Please select or write correct name!");
}
the function look for file refreshes index
void CL2HamsterDlg::lookforfile()
{
Value.GetWindowText(str);
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_SAVE);
pComboBox->ResetContent();
GetCurrentDirectory(MAX_PATH,curWorkingDir);
_tcscat_s(curWorkingDir, MAX_PATH, _T("\\Save\\*.dat"));
BOOL bWorking = finder.FindFile(curWorkingDir);
while (bWorking){
bWorking = finder.FindNextFile();
if (!finder.IsDots())
pComboBox->AddString(finder.GetFileTitle());
}
GetDlgItem(IDC_COMBO_SAVE)->SetWindowText(str);
}
so, in this case you do not need to use ResetContent(). Provided you already know the currently selected Item in the combobox (I think somewhere along the track you would have used the line int iSel = pComboBox->GetCurSel();) you could use this code IN PLACE OF YOUR pComboBox->ResetContent();:
pComboBox->DeleteString(iSel);
if(iSel < pComboBox->GetCount())
pComboBox->SetCurSel(iSel);
else if(iSel > 0)
pComboBox->SetCurSel(iSel-1);
However, I think this will not be necessary. I think the item will move by itself. So, forget about the code above, just use this:
pComboBox->DeleteString(pComboBox->GetCurSel())
I need to be able to select an index and have it visible. I can get the index to be selected but can't get it to scroll...
for (var _index:int=0; _index < registrarsAll.length; _index++) {
registrarsList.addItemAt(registrarsAll[_index].name, registrarsList.length);
registrarsIDs.addItemAt(registrarsAll[_index].id, registrarsIDs.length)
if(registrarsAll[_index].id == judgeID) {
judgesLB.selectedIndex = registrarsIDs.length-1;
}
}
judgesLB.scrollToIndex(judgesLB.selectedIndex);
The index gets selected but I can't get it to scroll into view. I am calling this on creationComplete. registrarsList is the data source for the list judgesLB.
thanks for any help.
John
I was able to get it to work in the updateComplete event of the judgesLB list...
updateComplete = "{((judgesLB.selectedIndex>13)?judgesLB.scrollToIndex(judgesLB.selectedIndex):null)}"
selectedIndex cannot be negative. -1 will generate an error.