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

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.

Related

Qt Widgets do not get showEvent() when tabbed in dock area of QMainWindow

In QMainWindow, when few widgets are tabbed together in dock area, how can I detect when a tab has been toggled by user? It is not a problem when I have an instance of QTabWidget created by myself and can attach a handler to currentChanged(), but what's about this case when the main window internally performs docking/tabifying operations? It normally would be showEvent() triggered but by some reason it doesn't work when tabs are switched. Also, a widget, not on active tab, has it's visibility state turned ON (isVisible() returns true) which is strange.
I found the answer. It is QMainWindow::tabifiedDockWidgetActivated() which is signaled when a tab on a docked widget changes. It was added in Qt 5.8. Without it there is no way.

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

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

Context Menu of TableView in Child Widget

I am programming in C++ in QT and trying to make a UI with dynamic tabs having tables inside each of them. For doing the same, I had my TabWidget in the main window, and another widget with just the tableView. As the tabs are dynamically being added to the main window by a button click, I make a new object of my widget and put it in that.
I also have another version of the application in which there are no tabs, just a tableView in the main window.
I am unable to open the context menu in the former case, while it works perfectly for the latter.
I am using the signal "customContextMenuRequested" in both the cases. Don't understand what I need to add for it to work when the tableView is in a child widget.
Some help please?
Thanks already!
Did you check that nothing is involving QAbstractScrollArea, it's possible that in this case it would signal/slot as expected.
This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. The position pos is the position of the context menu event that the widget receives. Normally this is in widget coordinates. The exception to this rule is QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport() .

Qt: mainwindow application

I would like to build an embedded Qt application. This application shall have a couple of windows which are invoked by button click. I don't know if I understood the concept of using qmainwindow in the right way:
Do I create one QMainWindow class and each other window that should be displayed is a widget placed as central widget or is any new window I call a new QMainWindow?
I do not use qmainwindow's tool, menu or status bar just the dock widgets which surround the central widget, like a header on top and a button bar at the bottom or a widget to the reight like a keyboard. Since the header's label stays the same (only the title and the icon changes) and the bottom bar always holds some button (which should call another central widget or return to the previous one), changing the central widget should be sufficient right?
Have a look at QT Layouts
http://qt-project.org/doc/qt-5.1/qtwidgets/layout.html
Remember you can nest layouts, so you probbaly want a VBoxLayout, and the second entry in that layout will be a HBoxLayout.

How to have common control in QTabWidget

I want to use a common control (QTreeView) in two different tab pages in QTabWidget.
how to do this ?
I added a tabwidget and controls in tab pages in Qt designer.
using qt creator version 2.4.1 in Win 7.
You can't have the same QTreeView in two different QTabWidget pages. When you add any widget to a layout, that layout takes ownership of the widget. Since there can only be one owner, you're stuck with one parent per widget.
But you can fake it. Give your main page a grid layout. Put a QTabBar running along the top, your QTreeView on the left (or wherever), and a QStackedLayout on the right. Connect the tab bar and the stacked layout so changing tabs in the bar changes the visible page in the stack layout.
That should be just what you're looking for - just be prepared to fight with QTabBar to get it to display like you want it to...
Alternatively, just live with having two separate tree views - they'll both be viewing the same model, after all, so the bulk of the data won't be duplicated. Saves you a fight with QTabBar, too.
Hope that helps!

Resources