PyQt4 (QTabWidget) how to change position of a Tab Page - qt

I am writing an application with PyQt and QT4. I am using a QTabWidget and have set my Tabs to closable and have connected the tabCloseRequsted signal to a method.
self.ui.tabWidget.tabCloseRequested.connect(self.onTabClose)
def onTabClose(self,index):
self.ui.tabWidget.removeTab(index)
This works fine as long as I only close the last Tab Page but if have say 5 Tabs open and close the second Tab the 3rd, 4th and 5th Tab also close. I suppose the way to work around this is to move the tab I want to close to the end so it has the highest index.
One other thing however. Users can create tabs, so when one is closed I don't know if there are one, two or ten tabs open.
How do I move a tab page? or even better is there a better way to close a Tab page?

OK, I found the problem my self. I had put the self.ui.tabWidget.tabCloseRequested.connect(self.onTabClose) in the same method as that which creates new tabs. This meant that if 5 tabs were created, then when one was closed the tabCloseReqested fired 5 times. By putting this connect statement in the init of my class like I should have done it is only defined once and only fires once when a tab is closed.

Related

Automated testing with Robot framework : RE Switching beetween windows that open on the same browser

Following the question : Automated testing with Robot framework : Switching beetween windows that open on the same browser a second issue arises.
How do I make it stay on the new tab if the original and the new tab have the same title.
I click the element, a new tab opens, then it switches to the original tab.
If I take out the Switch Window keyword, it stays on the new tab but it doesn't find the next element, I imagine because it is looking in the original tab.
Click Element //*[#id="id1"]
Sleep 3 seconds
Switch Window TAb 2
Wait Until Page Contains Element //*[#id="id2"]
Click Element //*[#id="id3"]
Sleep 20 seconds
Is it possible to solve this ?
You can try using window handles and switch to the particular tab
Identify and switch to first window
#{list1} get window handles
Switch Window ${list1}[1] -- this will switch to the latest tab opened

Simulating button click in Tcl/TK R package

I would like to simulate a button click to switch from one tab to another after a specific action has been performed. I.e. say there are two tabs, and I am currently located in the second tab. I click a button in the second tab which calls a function that changes the second tab to the first tab. I am not sure how to "mimic" the button click that Tcl/TK handles when switching tabs using the mouse. Is there a way to do this? Thank you!
Tab notebooks have a select method that does tab selection. Which tab to switch to can be chosen by a few schemes, but the important ones for most code are:
By index (counting from zero; 0 for the first tab, 1 for the second, ...)
By handle of managed child widget (often a frame, but not necessarily)

JavaFX how to check if mouse click triggered Tab selection

I have a tab pane that contains a bunch of tabs (obviously). Normally you can set a listener to each tab by calling setOnSelectionChanged() on the Tab. However, if the TabPane is being reorganized in some way, the tab pane automatically selects the first tab in the list. This is causing some performance issues for me so I would like to know if there is a way to know if a Mouse Click caused the Tab to be selected. Apparently tabs cannot have onMouseClick() listeners.
Whilst the solution to the answer wasn't found since tabs aren't actually nodes and don't have mouse click listeners, the performance issues were solved.
When changing tabs, I was (lazily) recreating the entire view and applying the model to the view. This caused a delay of approximately 140ms or more every time the tab changed. It was a bigger issue when implementing a search box to find the correct tab because as the tabs were being recreated from the search, the views were being recreating as the selection of the tabs changed (Tab pane automatically selects the first tab when adding new tabs).
Ultimately the design was changed to having the controller create the view once, and simply hooking the model to the view as the tab changed instead of recreating the view over and over.
I highly recommend looking at this post if your having performance issues and are relatively new to MVC/JavaFX programming:
Scene loads too slow
Currently changing tabs take approximately 15ms which is a significant improvement!

AutoIt3 find control handle not shown with AU3Info

Windows 10 SciTE 3.6.6
I have a window with a toolbar that contains a drop down that I am trying to get a value from but I am unable to find the window handle
The menu and item looks like this
I need to wait for a process to finish (but nothing is busy so waiting for a window does not seem to help). I know for sure that the process is finished if this drop down contains a 1, it will be blank while the process is running. I could also check if a sub menu item under Documents is enabled, but I have not been able to find a handle to the menu either.
When I drag the selector from AU3Info over the item outlines the main window and all values in the Control tab are blank

QMdiArea: First tab works fine, second tab's content is way too small

Situation: As the central widget of my application I have a QMdiArea in tabbed mode (wrapped in a custom class that inherited from QMdiArea). When I now add the first QMdiSubWindow via addSubWindow() everything is still fine, meaning the window and its contents are maximized to take up all the space of the QMdiArea. However, as soon as I add a second sub window, the following problem arises:
Problem: The content of the second window is not displayed, but instead the content from the first continues to (despite the fact that the second tab visually has the focus), but is reduced in size. It only takes up a few pixels. But if I now switch back to the first sub window/tab (either by clicking into the size-reduced widget which then automatically goes back to max size or by selecting the first tab header) and then selecting the 2nd again, all is fine = the widget/editor of the 2nd tab is now displayed and is maximized.
But only until I close the second tab, in which case the content from the first is displayed (as expected), but again only in the small size!
Screenshot:
Another related test case: 1st tab is created and is displayed full size as expected. If I now simply resize the overall QMainWindow, suddenly a faint border appears around the widget in my tab. So it appears to be in a mixed state between maximized and normal mode with borders. Does that create any new leads?
Screenshot:
I am so far not using any explicitly defined layouts, but given that the first tab works fine and after manual back-and-forth switching all others as well, I assume that it should work without.
Do I need to set explicit layout objects? Why does it work for the first tab, but not the second?
Some code as a base: This is the logic executed in my custom QMdiArea class that takes care of adding the new children:
// Note: pEditor inherits from / is a QMdiSubWindow itself
if(!pEditor->isInitialized())
{
pEditor->initialize();
pEditor->setWidget(pEditor->getEditorWidget());
pEditor->setInitialized(true);
}
pEditor->beforeDisplay();
addSubWindow(pEditor);
pEditor->showMaximized();
// HACK START
pExisting = subWindowList().at(0);
if(pExisting)
setActiveSubWindow(pExisting);
// HACK END
Update: Added the hack proposed by N1ghtLight. Marked as such in the coding.
Update 2: Edited / correct problem description + new test-case with screenshot.
After many hours of comparing the example project from N1ightLight to my own implementation, I finally came across the central differences. There were in fact two issues at play:
For some reason I had the following line in the creation of my MDI sub windows, which apparently screwed up the size handling. Getting rid of this line removed any need for the previously proposed hack. Combined with the layouting proposed by N1ghtLight, all size changes are now handled gracefully.
setWindowState(Qt::WindowMaximized); // do not use that state!
The second part regarding the tab closing (closing one tab did not bring up the next tab in the expected manner and size), is actually explained in the Qt documentation:
When you create your own subwindow, you must set the Qt::WA_DeleteOnClose widget attribute if you want the window to be deleted when closed in the MDI area. If not, the window will be hidden and the MDI area will not activate the next subwindow.
Since I was creating my own sub windows I had to set that flag, but I never did because I wanted to prevent Qt from automatically deleting my content widget as well. My solution now is that I set the flag, but whenever a MDI child is about to be closed, I remove the link to the widget, so Qt cannot delete it.
void CustomMDIWindow::closeEvent(QCloseEvent* pEvent)
{
setWidget(0);
pEvent->accept();
}
I will mark my own answer as the correct one, but will award the bounty to N1ightLight since his support eventually led to me finding the final solution.
The ugly workaround really can be the calling of setActiveSubWindow() twice: First for some available sub window and then for the newly created one. This should emulate the situation when you click on the first tab and then return to the second one.

Resources