slightly customized widget for PyQt4 with qtdesigner - pyqt4

I am creating an application with PyQt4 and I want to use qtDesigner to design the layout. The application contains a QGraphicView, for which I want to implement panning and zomming per mouse. The only way I know how to do that is deriving from QGraphicView overwriting the "mouse*" functions to do the panning and zooming.
Now I want to use this new custom widget with qtdesigner.
googling I find that I could write a "custom widget plugin" for qtdesigner. While it does not seem to be to difficult, I still find it overkill for such a little adjustment I want to make.
What other ways are there to customize a widget in PyQt4 when the layout is done with qdesigner?
Thanks!

You can promote your QGraphicsView to your own subclass
In the designer, right click on the QGraphicsView and select "Promote To" and fill the dialog with relevant information about your own subclass:

Related

How to use built in designer widget Icons for subclassed widgets in pyqt5

I've built lots of custom widgets to be used in Qt Designer, lots are just sub-classed standard widgets and I would like to use the standard icon. I can't find any reference to them nor could I actually find them on my system. If you leave out the icon function in the designer custom widget plugin, it will use a generic QT icon but that's it.

Qt Dockable windows snap to initial size when application central widget modified

I am building an app using pyqt5, where I have a central widget and several dockable widgets. The central widget consists of a QTabWidget and a pyforms ControlPlayer widget.
Whenever I resize any of the dockable widget and switch a tab in my QTabWidget, the dockable widgets get resized to their initial sizes. However, if I float around one of the dockable widgets and dock it right back then they don't resize, which is desirable for my application.
Can someone explain to me what is happening here? My guess is that some flag is being set on the central widget when I float the dock window, but I'm not sure which one
I came across the same in the manner: resized QDockWidgets snap back to their original form after the MainWindow is resized or something in my dockwidget is changed
(in my case: when tabs change within the dockWidget.)
This is, unfortunately, a bug and is not your fault.
I didn't find any fix for PyQt. The C++Community has a fix ready, but I guess I'm just to inexperienced in python to transfer that, since the self.resizeDocks doesn't seem to take my arguments.
see also:
https://bugreports.qt.io/browse/QTBUG-65592
or
QDockWidget splitter jumps when QMainWindow Resized

How to skin MFC main menu

I got a menu in an existing MFC application that has a standard MFC main menu.
But I would like to change its background colour so that it appears to more seamlessly belong to the rest of the application.
First picture: An MFC main menu. The application is skinned blue, as seen in the toolbar, but the menu is still standard grey background colour.
Second Picture: Spotify's menu, skinned to fit into the rest of the
colors.
I have not found any examples on anything similar. Could you please point me towards how to achieve this?
Approaches I thought of:
Subclassing CMenu to my own SkinnedMenu, but it is not created by our code but by a GetMenu() call in a mainframe class deriving from CFrameWnd. The only thing I can find here is its method signature, defined in afxwin.h so then how could I make use my own subclassed menu?
Removing the entire menu and add my own custom menu buttons, in a row, making it look like a menu. Maybe this is what spotify have done, as they have also removed the Windows window frame.
Editing the existing CMenu in some way, but the only customization I am able to find right now is modifying its MENUINFO. For example if I set info.hbrBack = skin.GetSysColorBrush(COLOR_MENU) the only colour that changes is the background of the dropdown, not the main menu itself.
Other :)

PyQt4 Qt Designer making dynamic GUIs

I'm trying to figure out a way of using Qt Designer to make a dynamic GUI. For example, let's say I have a main window with a horizontal layout. I have a push button on one side and an empty area on the other. When I click the button the empty area will be filled with a widget that I've made in Qt Designer. When the button is pressed again the widget will be replaced with another widget that I've made in Qt Designer. Would I have to go about making all my widgets, to fill the empty area, custom widgets?
I've tried setting the parent to the empty are, but on the second change I get this
QLayout: Attempting to add QLayout "" to QWidget "t2", which already has a layout
So then I tried deleting the layout but still see the old widget underneath the new one and the layout is now messed up.
help please
Never mind, figured it out. Simple really. Use QStackedWidget and as for the UIs made in Qt Designer wrap that in a class that inherits from QWidget.

QToolBar: Is there a way to add QAction to a QToolBar in QtDesigner?

I've a PyQt4 Installed on Python 2.6. I wish to insert actions or widgets into a toolbar in QtDesigner instead of adding them in code, with addAction or addWidget (as simple as adding actions to a menu in design time).
You can add actions by dragging them to your tool bar from the "Action editor" dock window. You cannot add widgets to the tool bar in Qt Designer, I'm afraid you'll have to do this from your code.
You can create your own widget plugins with new or extended functionalities.
Just follow the definition rules from the documentation .
I use a lot of custom widgets inside the Qt Designer.
Once you have figured out, how it works, it becomes a really power full method for your design work flow inside Qt Designer.

Resources