PyQt QTabWidget Multiple Corner WIdgets - python

I want to remove the actual Close, minimize and maximize buttons of a window and create my own custom buttons, just like in chrome. I therefore want to add corner widgets to my tabwidget. Is there a way so that I can add three buttons as corner widgets of a QTabWidget?
Is it somehow possible to achieve using the QHBoxLayout ?
The setCornerWidget function just takes one widget as its input.

Add a generic QWidget as the corner widget.
Give it a QHBoxLayout.
Add your buttons to the layout.
I use this frequently, often by subclassing QTabWidget and creating accessor functions that return the individual buttons. Adding signals like buttonClicked(int) with the index and buttonClicked(QAbstractButton) with the button itself are helpful, too.

Related

What is the best approach to merge two horizontal layouts and combine all widget together in a single layout PyQt5?

I know how to do it in Qt designer, but I am looking for this to do at run time.

Grouping multiple buttons with absolute positioning in a layout

Is it possible to group buttons that are arbitrarily positionned with PyQt ?
There is the context :
I would like to code a visual programm to control a research system with specific geometry, through Python.
I expect this kind of result :
In this program, the buttons of "buttons group 3" are positionned is a specific geometry that does not fit in a grid. Those buttons are clickable and a click on them change their color.
I would like those buttons to be grouped together, in something like a layout, because it seems to be that it is coherent in order to change positions and sizes of layouts and window if needed.
I'm coding that with PYQT5,... but I cannot figure in PyQt5 how to code this group of buttons with specific geometry ?
Is it possible to group buttons that are arbitrarily positionned with PyQt ?
Thanks in advance for your advice, I feel I'm missing something in PyQt concept.

PYQT Widget in Layout

I am Trying to figure out how to get a widget centered and fully shown in a layout.
The following code creates the widget and places it in the vertical layout just fine. However the widget is not centered in the layout and the bottom half is cut off.
widget = QtGui.QWidget()
FRM_widget = gsFRMPlaybackWidget.Ui_Form()
FRM_widget.setupUi(widget)
g_mainWindow.verticalLayout_mode.addWidget(widget,0)
The vertical layout is empty initially. I add a widget to it, then remove it later. The widget that is added is based on a combox selection. The contents and size of the widget will be different.
It will create the widget from another .py file (which is imported).
Is there some option for the vertical layout that I need to set? Is there an option for the widget I need to set?
Couldn't find anything that worked online.
I got to work.
In the gsFRMPlaybackWidget code (or designer) I had to set the forms layout to horizontally:expanding and vertically:preference for what I needed.

Exporting data and graphs from a python GUI into a single file

I have made a GUI with qt designer and python. In this GUI i have multiple tabs. In some tabs i display a matplotlib widget and in some tabs i display a textedit. After pressing a button lines will be plotted in the matplotlib widgets and in the textedit some data will be displayed. How can i get these matplotlib graphs and the data from the textedits into one file after pressing an 'export' button?
The question doesn't specify many constraints, but if one big honking image is sufficient, you can take snapshots of the relevant widgets using Qt5 or Qt4 and just tile them into gigantic image:
After calling QWidget::grab or Pixmap::grabWidget, find the most reasonable layout for all the widgets and calculate the total size. Then create one gigantic QPixmap and render them via QPainter::drawPixmap to the appropriate coordinates into the combined image.
Of course, this seems pretty ugly and questionable to me, but I'm not one to second-guess what you want to do either... just know that I realize this is kind of icky.

Best way to dynamically display several images as a list or table in Qt?

I would like to dynamically add and display images in a list or a table, probably with a scroll bar in Qt. However, I do not know what is the best choice to do so.
Qt provides an example called FlowLayout. Newly added widgets get automatically arranged in grid-like manner. When the window gets resized, the arrangement of the grid is updated to accommodate the new layout dimensions.
In Qt, it serves as an example how to implement your own layout class derived from QLayout. Find useful documentation here:
http://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html
Copy-paste the class and use it for example like this:
FlowLayout *flowLayout = new FlowLayout(this);
flowLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
for (int i=0;i<1000;i++)
flowLayout->addWidget(new MyWidget(i));

Categories