PYQT Widget in Layout - python

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.

Related

PyQt QTabWidget Multiple Corner WIdgets

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.

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.

PyQtGraph : how to change size (height and width) of graph in a ScrollArea

I'm trying to plot graph in a scroll area but I've no idea how to change the size of my graphs. Here is an example of what I have:
As you can see, in my ScrollArea (in Red) which as the size I want, I have a graph (well, in reallity I have more graphs and I want to see more then one (at least two) in this area).
So, I want the height of my graph (A) to be smaller and the width of my graph (B) to be expanding. Somine can help me ?
Thanks for your help !
It looks like your plot is inside a layout with the "Hide EMG" button. The widget holding that layout must be resized to fit the scroll area. You'll need to provide a code sample if you want more help than that..
Also consider using pg.MultiPlotWidget, which already provides similar functionality.
Adding to Lukes comment: A PlotWidget, which is probably what we see there, is a QGraphicsView, which is a QWidget. This is layed out using Qt. I'd recommend you to play a bit with Qt Designer to get an intuition on how the layouting works.
Another resource would be: https://doc.qt.io/qt-5/layout.html
For your explicit problem, if you do not want to get into Qt layouting, you could use QWidget.setMinimumHeight and QWidget.setMaximumHeight to confine the widget vertically. For the horizontal part, that totally depends on what you are doing there. If that was a grid layout, I'd refer to e.g.: Expanding only one column in a QGridLayout

Adding many scrolledpanels to one scrolledPanel in wxPython

Level: Beginner
I am developing a GUI with wxPython on Windows 7 OS. Python version is 2.7 ad wxPython version is 3. My GUI looks as shown in the image below:
I would like to take some time to explain what I am trying to achieve. As you mayhave noticed from the first image that there are 4 different scrolled panels in my GUI named as panel-1 to panel-4. A vertical BoxSizer is applied to each scrolled panel. Each scrolled panel in return contains a boxsizer and a horizontal wx.StaticLine. The reason for using horizontal line was to make it is easier for the user to read the values for a particular serial number. (It will be easy for an user to read all the values in different panels for a particular serial number.) Finally all these four scrolled panels are added to a horizontal BoxSizer named as panelSizer. Currently the scrolled panels are scrolling individually. One important thing is that all the scrolled panels will every time contain same number of components/elements.
Problem:
I need a way so that I can add all these scrolled panels to one sizer or a panel in such a way that there is only one scroll bar at right side and when I scroll this scrollbar all the scrolled panels (panel-1 to panel-4) should scroll simultaneously. I would like to have something like this:
I think this option is better from the GUI perspective. I have tried couple of things like, I created a new scrolled panel named as main panel, and applied the BoxSizer named as panelSizer (it contains all the panel from panel-1 to panel-4) using SetSizer() function, but the scroll bar doesn't appears, even the individual scroll bars doesn't appear! Also, I have checked that there are enough components in the panels so that scroll bars appears. I tried to change the four scrolled panels to simple panels and then add to the panelSizer and then applied the sizer to the main panel but nothing solved the problem..
Can anyone suggest what is wrong with my approach? Any suggestion. Thank you for your time.
Well I found the solution myself so here it goes.
I have to disable scrolling on the panels-1 to panel-4. This can be done by not using SetupScrolling() method on them. Also, the scrolling should be enabled on the mainPanel like this:
mainPanel.SetupScrolling()
For an example: Consider that you have two scrolled panels named as panel1 and panel2. Now if you want to add these two scrolled panels to an other scrolled panel named as mainPanel, then you first create these two scrolled panels and then disable scrolling on them then add these two panels two a sizer, then apply this sizer to the mainPanel.
Code example:
mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1,style=wx.SIMPLE_BORDER)
mainPanel.SetupScrolling()
panel1 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
panel2 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
panelSizer = wx.BoxSizer(wx.HORIZONTAL)
panelSizer.Add(panel1)
panelSizer.Add(panel2)
mainPanel.SetSizer(panelSizer)

embedding grid in panel in wxpython

What is the proper way to embedd grid (wx.grid.Grid) into the panel? I tried the following code and got bizarre frame:
wx.Frame.__init__(self,wx.GetApp().TopWindow,size=(600,800),title='Material Properties')
self.GridPanel=wx.Panel(self,-1)
grid=wx.grid.Grid(self.GridPanel,-1)
grid.CreateGrid(10,10)
I cannot see an easy way to create a grid which can also have buttons as well as menubar and other related widgets. Is there any example which shows GUI of how to implement wx.grid to achieve some sort of spreadsheet which has tabs on it for manipulation. I seem to be lost on this.
I want to create two different grid and also want to add some buttons and additional functionalites to the frame containing the table. Is there any better way to do that in wxpython?
I wrote about grids quite a while ago on my blog. You might find the following articles helpful for putting a Grid onto a Panel:
http://www.blog.pythonlibrary.org/2010/04/04/wxpython-grid-tips-and-tricks/
http://www.blog.pythonlibrary.org/2010/03/18/wxpython-an-introduction-to-grids/
Once you have that figured out, you can easily put the panel into a Notebook. If you want to add buttons, create the buttons and then add them to the sizer (see second example). Adding a Toolbar to the frame is covered in the wxPython demo, but I covered it here too:
http://www.blog.pythonlibrary.org/2008/07/02/wxpython-working-with-menus-toolbars-and-accelerators/

Categories