How can I design a second widget with the QT-designer, when i have allready a widget at that position? - qt

I want to make a gui with QT-creator 4.9.1. Designer. My window has 5 widgets, one of these widgets must be change his visibility everytime when the user select a other menu. For that i have made a widget namded workingarea inside my window and inside the workingarea-widget i have a second widget named workingplace0001. My problem is now, that i don't know how can i create the second widget, because i can't change the visibility from the workingplace0001 widget to false. Is there any possibility to change the visibility so i can create the workinplace0002 at that place or can't i use the Designer for that?
I must create 69 workingplaces

You can use QStackedWidget. Just place it in on your main widget, then add number of pages you need, and then place every workingplace on every page of QStackedWidget. For changing current workingplace just change active page of QStackedWidget

Related

Is there a way to create two independent layouts in Qt Designer?

I am new to Qt Designer so this question may be stupid but I'm really stucked.
I'm creating an app using Qt Designer and PyQt5. My app contains a few screens and I want to switch between them by clicking the button.
The first screen consists of a button (button_1) and a label (label_1) placed in a vertical layout. The second screen also consist of a button (button_2) and a label (label_2), but these are different widgets with different size and content. And I want to place button_2 and label_2 in a horizontal layout.
Previously I didn't use layouts. I just created one .ui file and put button_2 and label_2 above button_1 and label_1. They were overlapping but it didn't affect the performance because I made the button_2 and label_2 invisible when button_1 and label_1 are shown and vice versa. But now I need to make the window resizable, and I need to put the widgets in a layout.
The first thought was to create two separate .ui files and set them using loadUi command when it comes to switching between screens. But I need to use just one .ui file. Is this possible? How can I create two independent layouts? Or maybe there is another way to solve my proble. Any help is very much appreciated.
I think that in this case your best option is to use a QStackedWidget as a container for your labels and buttons. To create a stacked widget in Qt Designer you can drag a Stacked Widget from the container group on the left to the parent widget. This will create a stack with two pages. Each page can then be set up independently. Whatever layout you and widgets you add to a particular page will only be visible when that page is shown. You can add additional pages if you like by right-clicking on the stacked widget and selecting Insert Page from the context menu.
To navigate between the pages in Qt Designer you can choose the correct widget in the tree in the Object Inspector, use the two black arrows in the top-right corner of the stacked widget, or use the context menu of the stacked widget. To navigate between the pages in your python script you would need to use QStackedWidget.setCurrentIndex().

How to open editor outside of qlistview?

The QAbstractItemView::openPersistentEditor method calls the createEditor method reimplemented in a class inherited from the QStyledItemDelegate class. It opens a widget inside the current item. But my task is to show the editor widget in some custom way. Say, under the current item, but with it's right border outside of the scroll area of the view. And it's height being far more, than just one item's height. Is there any way to do it?
It opens a widget inside the current item because the current item its parent.
One of the solutions is the following: you provide a simple editor widget which is shown inside the current item, which really does not provide editing, only data exchange.
But this editor widget creates custom widget as a dialog or as a widget whose parent is the topmost ItemView. Or you can delegate the creation of the custom editor widget to the ItemView. The result of the editing is sent to the in-item editor widget which does the job of providing the ItemView with newly edited data.

How to know the active Qt Widget in the current window?

The application I'm working on has a QTabWidget with 3 tabs, and all the tabs have QStackWidget added to it with variable number of widgets present at a time.
When I RMB on a particular widget inside a particular tab, its eventFilter gets called and a context menu pop up.
I have to add this RMB context menu behaviour on top as Banner Menu. And this Banner menu is not written in Qt but in some internal which can be converted into C++ using wrapper.
Now my problem is that when I RMB on a widget its eventFilter easily tells me address of the object ie: this and I can add appropriate slots to context menus.
But in the case of banner menus, how would I know the address of the object whose slots() I have to call. The banner menus are supposed to work for the selected/currently-visible widgets.

What is the best way to change type of widget on-the-fly?

I need to show different information at the same place depending on user's actions.
For example, if one button was pressed, I need to show QTableWidget, if another button was pressed, I need to show QListWidget on the same place.
What is the simple and good way to do that thing?
What you need is called QStackedWidget. Fill it with necessary widgets and use.
You can delete the existing widget, create the new one, and add it to the layout in the same place. Or create both widgets but only show() one and hide() the other.

Keep widget on top in Qt

I'm creating an application which has a "floating" widget which can be dragged around inside the application window. But it starts up, or tends to go behind other widgets sometimes. Is there any way to make sure that the widget in my application stays on top of all other widgets whenever it is made visible?
Thanks.
Use the flag Qt::WindowStaysOnTopHint for your QWidget. This will force your widget to stay on top of all other windows
You can call raise() on your widget to make it appear in front of all other child widgets of the parent it is in. If I read your question correctly, this is the behavior you want. However, any child you create and add to a parent widget will automatically be placed above that widget, so you may need to reraise the widget after additions, or you may want to consider an alternate way of managing the parent/child relationship.

Resources