Set the size of wx.GridBagSizer dynamically - python

I'm creating an app where I drag button widgets into a panel. I would like to have a visible grid in the panel where i drop the widgets so the widgets will be aligned to the grid.
I guess it isn't hard making a grid where the squares are 15x15 pixels using a GridBagSizer(since the widgets will span between multiple cells), but how can the number of squares be made dynamically according to the size of the panel?
Do I have to calculate how many squares i need to fill the panel on init and on each resize?
Using python and wxpython btw.
Oerjan Pettersen

Don't use a sizer at all for this. Just position the buttons yourself, with whatever co-ordinate rounding you like. (using wxWindow::SetSize()).
(The point of a sizer is that the buttons will get moved and/or resized when the window is resized. As you don't want that behaviour, then you shouldn't use a sizer.)

Related

Create and align non-rectangular widgets together with PyQt6

I need to create a widget/layout, which will contain a number of non-rectangular, clickable widgets that are well aligned together so that they create a whole (picture below).
Each of theses widgets needs to be clickable and have a hover option. I thought of using QAbstractButton or QPushButton class and overriding it's paintEvent to draw it with a particular size and shape, but I don't know if this is a optimal solution. I also have no idea how I could then align these widgets together so that there are no empty spaces between them. I thought of using some absolute position of a parent Window and manually adjust child widgets position based on that.

Python QT5 - QTWidget Layout grow/shrink to maximumSize/minmumSize

I have a layout question for python with qt5.
So, there is a main window with a normal vertical layout with 2 widgets.
The first one is a widget with a scrollarea which has a minimumSize & maximumSize set.
The second one is another widget with yet another scrollarea widget.
My goal is this. I load some content in the first widget and depending on the content it should either shrink or grow to the set min/max sizes and if it gets bigger than maxsize the scrollarea should take effect.
The second widget should always take all the rest of the available space.
I've tried all kinds of sizePolicy combinations but can't get it to quite to work. The second widget has a sizePolicy of Prefered/Prefered with vertical stretch set to 1, so it takes all the available space for itself.
The 1st widget has a miniumSize of 100 and a maximumSize of 250. So ideally it should shrink to something between 100-250 if the content is less and it should grow to 250 and activate the scrollbar if the content is getting bigger.
If I update the content of widget one (i.e. by clicking on a button) it should 1. resize/shrink/grow so the content fits, but not smaller than 100 and not larger than 250. If I have less content I should not be able to make widget one reszie to 250 - it shoudl always just take the exact needed height.
Any idea on how to do that?
example layout
Your scrollarea isn't going to change size, because it's a scrollarea. It doesn't need to size itself to its content, because the size of the contents of a scrollarea is basically unbounded. You can just scroll more. If you want to change the size of the first scrollarea, you're going to have to set its height manually.

PyGTK/Glade keep button size standard

I have a simple pygtk/glade window with a menu and a 3x3 grid. Each row of the grid consists on: two labels and a button.
When the Window is resized, the labels holds the same font size, but the buttons get resized, and they could become HUGE if the windows gets very big.
How could I manage to keep my buttons with the same size always (the "standar" size of a button, just like they are when the interface is just opened) no matter if the Window is resized?
You just have to set the fill and expand parameters of the Buttons to False (uncheck them in the Glade interface).
You would also want to put each button at the center of a 3x3 GtkTable, so it will appear centered and not aligned at the top of the cell

Setting an initial width of a pyqt widget in a splitter

I am using python and PyQt to design a simple interface.
My question is this:
How do I set an initial width of a pyqt widget in a splitter while still allowing it to be modified by the user when they drag the divider?
I want one of the two widgets in the splitter to be narrower when the application first launches and I also want the user to be able to manually change the width by dragging on the divider. I tried setting the maximum width in Qt-Designer and then when the application launches the widget is narrower but you can not drag the dividing line to expand it. If I don't set any maximum widths then when the app launches they each take up 50% but I can drag the divider around manually to adjust the ratio.
Did you try?:
QSplitter.setSizes (self, list-of-int list)
###Sets the child widgets respective sizes to the values given in the list.
You have here a working example

Resizing frames in Tkinter

I have been making a small program with the Tkinter module in python, and I was wondering whether it was possible or not to resize a frame in my program with the mouse. As in, the user can drag the frame border and it will resize itself.
Your use of terminology makes the question unclear. Windows which may be resized by the user are called Toplevel windows. These are what appear as rectangular windows on the display, with a frame around them, typically a title bar, and edges or corners that can be grabbed and resized.
The term Frame refers to a container widget that must be inside a Toplevel or one of its descendents. A Frame has the ability to be resized but you have to write the code to let you interactively resize them. For example, you could place a little grip widget in one or more corners, and writing bindings to the press, motion and release of a mouse button.
Depending on the effect you are looking for, you might want a PanedWindow which is a container that includes a sash that lets you adjust the proportion of space between two other widgets.

Categories