QTableWidget Expand Columns to Fill With Last Column Fixed Width - python

I'm attempting something that I thought would be simple, but just cannot find a way to do this.
The supplied image demonstrates what I'm after. It's essentially just a QTableWidget with the following behaviour:
Fill the available space.
A fixed width column on the right.
The rest of the columns I'd like to be able to resize manually (so they'd have to stretch proportionally so that all space is filled).
Things I have tried:
Setting setStretchLastSection(True). This fills up the space, but you have no control over its width if this is set.
Overriding the resizeEvent and calculating and setting everything manually. This seems like a very messy way of doing things, which usually means there's a simpler way.
Is there a simple way of achieving this?

You can always ResizeToContents all columns with self.my_table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) and then apply your fixed width to the last one

I managed to get something that works
self.myTable.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.Interactive)
self.myTable.horizontalHeader().setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
self.myTable.horizontalHeader().setSectionResizeMode(2, QtWidgets.QHeaderView.Fixed)
The general rule is to set all of the headers to Interactive, the penultimate to Stretch, and final to Fixed.

Related

Python pptx insert a picture in a table cell

Is there a way to insert a picture inside a cell using pptx python?
I'm also thinking of finding the coordinate of the cell and adjust the numbers for inserting the picture, but can not find anything.
Thank you.
No, unfortunately not. Note that this is not a limitation of python-pptx, it is a limitation of PowerPoint in general. Only text can be placed in a table cell.
There is nothing stopping you from placing a picture shape above (in z-order) a table cell, which will look like the picture is inside. This is a common approach but unfortunately is somewhat brittle. In particular, the row height is not automatically adjusted to "fit" the picture and changes in the content of cells in prior rows can cause lower rows to "move down" and no longer be aligned with the picture. So this approach has some drawbacks.
Another possible approach is to use a picture as the background for a cell (like you might use colored shading or a texture). There is no API support for this in python-pptx and it's not without its own problems, but might be an approach worth considering.

Using exact positions for PushButtons and still be able to scroll through them

First of all, check out this screenshot to see what I'm talking about.
Part A is much longer than shown (hundreds of rows - each row consisting of a label, 2 squares, another label and a checkbox). Now I want to add a scroll bar for part A, so all the rows can be viewed, while part B stays where it is.
It seems the solution to this is using layouts.
I haven't used them so far, simply because I didn't know they existed and I'm still not sure how they work exactly. I'm new to Python and PyQt (and programming, for that matter).
The problem with using layouts is that the squares in part A (which are PushButtons, btw) need to be positioned exactly (by pixels), instead of arranging them along a grid.
Is there a way to add a scroll bar for part A without having to use layouts?
-or-
Is there a way to give the squares an exact position within a layout?
I found a solution without having to use a layout. I put everthing in part A into a QWidget and put the QWidget into a QScrollArea. There may be better solutions, but this worked. The scroll bar doesn't have to be added manually. It appears when scrollContent is larger than scrollArea.
scrollArea = QtGui.QScrollArea(MainWindow)
scrollContent = QtGui.QWidget()
scrollArea.setGeometry(0, 0, 700, 600)
scrollContent.setGeometry(0, 0, 680, 25000)
# Here I add all the content. E.g. label = QtGui.QLabel(scrollContent)
scrollArea.setWidget(scrollContent)
I hope this is helpful to someone.

Force label line wrap

I'm using a Gtk.Label within a tooltip to display text. The text is usually rather short, but does occasionally become very long, in which case the label expands horizontally to fill the entire screen width, which results in a ridiculously wide tooltip. Is there a way to force the label's text into more lines?
I had two ideas:
1) set the label's maximum width. Gtk doesn't seem to support this.
2) set the label's maximum line length. Gtk doesn't seem to support this either.
Which means I'm fresh out of ideas. Is there any way to do this?
Use gtk.Label.set_line_wrap combined with gtk.Label.set_max_width_chars.
Example:
label.set_line_wrap(True)
label.set_max_width_chars(20)

wxPython: how to lay one panel over another

This is about wxPython.
I would like to have 2 Panels laying one over the other:
PanelBG should be some sort of a "background", with its own GridBagSizer with subPanels, StaticTexts and so on;
PanelFG should be the "foreground" panel, also with its own GridBagSizer with some StaticTexts, Buttons... but a transparent background, in such a way that PanelBG is visible wherever PanelFG doesn't lay widgets.
I need both Panels to stretch to all the sides of the frame, even when resizing the window, though never changing the reciprocal proportions, that's why I'm not sure if there's a way to use absolute positioning.
In case you are wondering, the reason why I don't want to use a single Panel is that merging the 2 GridBoxSizers would require me to place many many more cells in the sizer, because rows and columns of foreground and background don't always coincide, and I should split them in many cells, with grid dimensions growing up to hundreds**2.
Since the content I want to put in the foreground needs to be updated and refreshed quite often, this would require redrawing all the cells every time, which would take 10 - 20 seconds to complete the operation (tested). Updating only the foreground would require just some hundredths of a second instead.
Thank you!
This would be at least partially a change of direction, but it might be worth examining what other rendering options you have.
In particular, I'm thinking of wxWebKit (http://wxwebkit.kosoftworks.com/), which would let you do layering, etc. using the WebKit browser rendering engine. I'm not sure whether it's at a stage that would provide everything you need since I haven't actually used it, but even if it doesn't work then it may be an approach worth trying - using HTML/CSS for part of your display, while wrapping the whole in a wxPython app.
As I understand it, this is a calendar with rectangles for the days containing the events for the days.
The simple thing would be to use a wxGrid, with seven columns and four or five rows, to represent the months. You would then place the events into the grid cell for the correct date. The wxGrid widget would look after the details of refreshing everything properly.
Using wxGrid you might lose a little control over the exact appearance, though wxGrid is very flexible and feature rich once you learn its many methods, but you would save yourself having to write large amounts of code that would require significant effort to debug.

How to make two elements in gtk have the same size?

I'm using pyGTK. I want to layout a large element with 2 smaller ones on each side. For aesthetic reasons, I want the 2 smaller ones to be the same size. As it is, they differ by a few pixels, and the middle element is not centered as a result.
I tried using gtk.Table with 3 cells, but having homogeneous=True doesn't have the desired effect. I tried messing with it by making 8 cells, and then having the center one take up more cells, but it doesn't work well. Is there any way to do this?
You should use GtkSizeGroup for this. Create a GtkSizeGroup, add both widgets to it. This will ensure that both widgets have the same size. If you want that widget have the same size in only one direction (width or height), set the "mode" property of SizeGroup.

Categories

Resources