PyQt4 Qt Designer making dynamic GUIs - pyqt4

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.

Related

PYQT change clearButton in QLineEdit (w/wht Qt Designer)

Since I updated python from 3.8 to 3.10 (with Linux Ubuntu 22.04), clear button in QlineEdit widget has become an ugly red cross. It was before a nice dark kind of rectangular button with a small cross inside.
I wish I could switch back to the previous clear button without having to create a custom button, because the red cross is kind of disturbing as it seems to indicate an error in what you write in the QLineEdit widget.
Is there a way to do that in Qt Designer or programmatically?
It seems a bit unlikely that just updating Python would affect the icon.
The update probably involved other packages along with it (or they need rebuilding, they were uninstalled due to incompatibilities, etc), so I'd suggest to check that first.
In any case, you can set the icon using a specific stylesheet you could set for the top level window or even the application, so that it will be used for any QLineEdit with the clear button enabled:
QLineEdit > QToolButton {
qproperty-icon: url(/path/to/icon.png);
}
Note that this will override all icons of QLineEdit, including those used for custom actions, so in that case you must explicitly set the object name of the button and use the proper selector in the QSS:
# this assumes that the clearButtonEnabled property is already set,
# otherwise it will crash
lineEdit.findChild(QToolButton).setObjectName('clearButton')
lineEdit.setStyleSheet('''
QLineEdit > QToolButton#clearButton {
qproperty-icon: url(/path/to/icon.png);
}
''')
Also, see this related answer for other alternatives.

Layout management inside Cairo DrawingArea/Context?

I have a window in mono gtk#, which has lot of VBoxes & HBoxes. These boxes contain some buttons, labels, and some other widgets also. Now I need to make this window alone to transparent.
I created one drawingArea by referring zetcode page.
But inside this drawing area I'm not able to do the arrangements of my widgets, one Move function is available, but it is not much use for me. So how do I do widget arrangement neatly inside a drawingArea?

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 :)

slightly customized widget for PyQt4 with qtdesigner

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:

Resources