Hide a tab previously added to Qt TabWidget - c++

I've a dialog which contains a Qt TabWidget with a number of tabs added.
I'd like to hide one of the tabs.
_mytab->hide()
doesn't work. I don't want to just delete the tab and all its widgets from the .ui file because other code relies on the widgets within the tab. However, it would be fine to generate the tab code but somehow not ::insertTab in the generated uic_mydialog.cpp. Setting the hidden property in the ui file does not work either.
I'm using Qt 3.3

I had encountered the same problem. I am using the following approach.
Now here is the data.
genTab is the name of my QTabWidget
tabX is the name of the tab that i want to remove.
(Note that this is the second tab in the Tab Widget. Hence, i will be using "1" as the index to refer to this tab)
The code to remove and add is as below.
ui.genTab->removeTab(1); // removes the tab at the index 1 which is the second tab from left
ui.genTab->insertTab(1, ui.tabX, "<Name of TabX>"); // The tab is added back.
Here, note that it is easy to do this if you have the tab added statically in the design time. Because we will have an object name associated with the tab and hence we can refer to it using, ui.tabX. From what you say, in your case the tab is indeed added statically in the design time.
However, if you are adding the tabs dynamically, then probably you will have to maintain the tabs in a list and then have another list for deletedTabs.
But the first solution will most likely work for you.
Hope this helps.
-Arjun

I would use QTabDialog::removePage(QWidget* pTabPage) which does not delete pTabPage, which is what you want.
_myTabDlg->removePage(_mytab);
I'm using it and it works fine !

Related

Desktop Navigation Menu, How to fix the problem when you click?

help please, I can not understand what the problem is. When you click on the drop-down menu, opens a completely different tab, which is located above.
The page itself opens correct.
But the menu unfolds is not correct.
What i want to see
Any thoughts? Maybe this is done in the settings?
To edit the Menu you go into Shared Components-Navigation Menu.
Not sure what your problem is, but it could be something to do with how those are sorted.
What you need is for all the top layer tobs(the ones you have w/o names) to have no parent, and each have its contained tabs marked with it as parent.
And maybe try changing their sequence so that all the second layer tabs are in sequence between the top layer tabs(say your first top layer tab is sequence 1000, and your second top layer tab is 2000, make sure all the second layer tabs belonging to the first top layer tab are marked with the correct parent entry, and are numbered between 1000 and 2000).
I hope this resolves whatever bug you have.

How to change the sequence in the MDI Tab document menu?

In the tabbed document view of the MFC feature pack the user can re-order the tabs by dragging and dropping and when there is a larger number of tabs in use you have a drop down list at the end.
The problem is that the menu item for windows with the drop list of the first 9 sessions and more windows, plus the drop down list at the end of the tabbed bar are in document load order.
Does anyone know of a example on how to change the Document order in the CDocManager class in order to stay in sync?
The relevant code can be found in CMFCTabCtrl::OnShowTabDocumentsMenu.
So reorder the internal array and you have what you need.
You have the source code so it shouldn't be a real big thing.
You can use following code for it:
CMFCTabCtrl &t = ((CMainFrame*)m_pMainWnd)->GetMDITabs();
t.MoveTab(<your tab number>, t.GetTabsNum()-1);

Transfer form elements between tabs on scope change in Qt

My problem is quite simple: I need to transfer form elements from one tab to another.
Say I've ten tabs and each tab has it's own set of text edits.
Is it possible to create just one set of text edits and transfer it from one tab to another,changing functionality behind it, but without changing the forms layout?
Currently I've "solved" that problem just by populating copy of text edit's for each tab but common sense tells me that there's a simpler way to achieve that in Qt.
I'm using Qt 5.7.
Yes, it's possible using a single QTabBar. A QTabBar, as its name suggests, only displays a narrow bar with multiple tabs within.
You can put a frame below that tab bar and listen for tab change signal which is emitted by the QTabBar. In this way, the frame below is the same for all tabs, so you can change underlying logic for each tab.

Tab order in Qt

I have complicated UI created with Qt Designer. It has a hierarchy of nested widgets. I need certain tab order to switch between controls inside these widgets. But as far as I see, Qt designer allows to define tab order only within one widget. How to do it globally?
open the Edit menu and select Edit Tab Order. In this mode, each input widget in the form is shown with a number indicating its position in the tab order. you can click on the box number and change the priority.by right click you can see 3 options, start from here, restart and Tab order list.

How to create an editable list of items in Qt Designer?

I'm using Qt Designer to create a Qt 5.4 GUI application (actually, I'm using Qt Creator 3.3.2 but haven't done any C++ yet; everything is in the .ui file).
I'd like to create a box containing an (empty) list of items from which the user could double click inside the box to add a new element to the list (can be single click or other, doesn't really matter).
I just can't figure out how to do this only through the designer. I've checked the properties of the "List Widget (Item-Based)" and "List View (Model-Based)" and there is some options in "editTriggers", but even with the default "DoubleClicked" checked, the compiled application does not allow adding a new element (or deleting...)
Any easy way to achieve this using only the Designer (without doing C++)?
Or is there another widget that would be better suited for this?
Thanks!
If you want to make such a widget, that can be setup completely in the designer only, you are asking a little too much.
If you start with a List Widget and add a bunch of empty named elements, and then make all of them editable, it will seem like you can just double click to add an element.
To make an existing element you've added in the list editable, (in the designer) double click your List Widget, then
in Edit Widget List, click the plus sign, followed by Properties. Scroll down to flags, then check Editable.
This needs to manually be done for each item added.
The C++ to add what you are asking for is very painless.
Add a Push Button. Rename it's objectName to addItemButton.
Then right click on it, and select Go to slot....
Select clicked(), then click Ok.
Now put the following in the slot:
void MainWindow::on_addItemButton_clicked()
{
QListWidgetItem * item = new QListWidgetItem("New Item");
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->listWidget->addItem(item);
}
Done.
Hope that helps.