Gtk scroll window size in a grid - python

Experimenting with Gtk+3 in python.
Trying to add a "Gtk.TreeView" inside a scroll window container to a grid window along with an entry box. The problem is that the scroll area is tiny and as a result you can barely see any of the scroll window/TreeView. Here is an image of the output:
The relevant code is:
scroll = Gtk.ScrolledWindow() # Create scroll window
scroll.add(self.MatchTree) # Adds the TreeView to the scroll container
grid = Gtk.Grid() # Create grid container
self.add(Grid) # Add grid to window (self)
Grid.add(scroll) # Add scroll window to grid
Grid.attach_next_to(self.Entry, scroll, Gtk.PositionType.BOTTOM, 1, 1) # Attach entry to bottom of grid.
So how do you control the size of the scroll area?
Cheers,
Phil

What you need to do is to set the hexpand and vexpand attributes of the GtkScrolledWindow to True. You can do this on object creation like this:
scroll = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
If you are up to it, I recommend you use Glade to work your program's interface, it makes a lot simpler to work out this kind of problems, since you have easy access to all the widgets properties.

Related

PyQt scroll Area with custom widget and spacer

I want to make a list of custom widget vertically aligned, where I dynamically add the custom widget inside a scroll Area.
If I click on "add image", a custom widget is added to the scroll area with vertical layout.
like this :
Note that I didn't succeed to make the scroll Area expand as I add widget inside, I had to put a big minimum height to make a scrollbar appear.
The second issue is, when i add like this my widget they are spaced to much, and not added under each other. To prevent this I tried to add a vertical spacer. However, with the vertical spacer, the widget added by clicking on "add image" does not appear anymore (I use insertWidget(Vlayout.count()-1, mycustomwidget)
I organised everything like this :
the pushbutton is an example, I add my custom widget here.
Why the scroll Area doesn't expand as I had widget ? I tried :
self.scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.scroll.setWidgetResizable(True)
Why, when I had a spacer, the widget does not appear anymore ?

how to auto resize in pyqt4 python?

I want to auto resize the above picture at the size shown below when user resize the main window.
Is there any function to do this in pyqt4?
I was searching for an answer to this problem... but i can't find something related.
I've tried to set fixed minimum size but this doesn't work.
How to auto resize a window in pyqt4 (python)?
pictures is got in qtdesigner.
If you are using the QtDesigner, then its really easy. Have a look at layouts like vertical layout, horizontal layout
Follow step:
1. Add layout to your main window.
2. Right click main window and click 'layout vertically' as you want button below
the text area
3. Then add(drag-n-drop) your text area inside vertical area.
4. Add button and what not....
5. Have a look at 'http://doc.qt.io/qt-4.8/designer-layouts.html' google for
properties of layout like alignment of element. size, orientation.

Can I draw on top of a canvas inside of another canvas?

I am creating a Solitaire clone using Python's Tkinter window toolkit. My window contains a main canvas, and within the main canvas a series of widgets that inherit from Canvas that hold the cards. I have implemented a "Drag to Move" system where a user can click the mouse down to select a card in one of the inner canvases, drag it to a new canvas, and let go to place the card into the receiving canvas.
The Problem: I want to draw the cards in motion between the canvas on which they are drawn, and the canvas they are moving to, so the user can see them moving across the screen during the click and drag motion. When I try to draw cards in-between the canvases that I already have, they are always drawn behind, meaning I can only see cards through the padding around the inner canvases.
Here is an example where I drew several of them so the effect could be seen clearly, and the inner canvases are also clearly visible.
What I've Tried: I've tried to move the canvases back using Misc.lower(aCanvas), but i wasn't able to create the desired effect. I've also tried to design a custom overridden cursor, but it seems my cursor size is limited to 32px*32px, which is insufficient for the size of the card images I want to move.
My Question: How can I draw on top of a canvas that is inside of another canvas? If I can't, how would you solve this problem?
You cannot do what you want. Embedded widgets are always above the canvas items.
Why is it that you are embedding canvases insidebcanvases? Why not just use a single canvas?

How to make a wx Toolbar buttons larger?

I've got a wx.Toolbar and I'd like to make the buttons larger. I've searched and can't seem to find any concrete documentation on how to do this.
I'm also wondering how well this will translate across platforms; what will happen to the buttons and icons on OSX?
It depends on what you want to change: is it the size of the buttons or the size of the icons ?
To change the size of the buttons, use SetToolBitmapSize (24x24 for instance):
toolbar.SetToolBitmapSize((24, 24))
This will only change the size of the buttons, though. If you want to change the size of the icons, simply use bigger ones. The easiest way is to use wx.ArtProvider:
wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, (24, 24))
So, summing it up:
# Define the size of the icons and buttons
iconSize = (24, 24)
# Set the size of the buttons
toolbar.SetToolBitmapSize(iconSize)
# Add some button
saveIcon = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, iconSize)
toolBar.AddSimpleTool(1, saveIcon, "Save", "Save current file")
Remark: As SetToolBitmapSize changes the size of the buttons, not the size of the icons, you can set the buttons to be larger than the icons. This should leave blank space around the icons.
Doesn't the size of the toolbar adapts itself automatically to the size of the bitmap icons? I think if you want a bigger toolbar, you need bigger bitmaps.
On Mac OS X Big Sur running python 3.9 and wxpython 4.1.1. this call
toolbar.SetToolBitmapSize((24, 24))
does not work. The algorithm seems to be that of the icons associated with the toolbar wxPython picks the largest one and sets that size for all the other icons.

wxPython: Making a scrollable DC

I am drawing inside a wx.Window using a PaintDC. I am drawing circles and stuff like that into that window. Problem is, sometimes the circles go outside the scope of the window. I want a scrollbar to automatically appear whenever the drawing gets too big. What do I do?
Use a wx.ScrolledWindow and set the size of the window as soon as your 'drawing go outside' the window with
SetVirtualSize(width,height)
If this size is bigger than the client size, then wx will show scrollbars. When drawing in the window make sure to use CalcUnscrolledPosition and CalcScrolledPosition
Here you can find some more information.

Categories

Resources