PyQt5 - Make labels in a grid expand dynamically without covering other items - python-3.x

I have a QGridLayout instance in a window, to which I dynamically add a series of widgets, depending on which values are checked on another QListView instance.
For each checked item in the list, I add a slider and two labels (for value and name), on a row of the layout, in positions 0, 1, 2.
for index in range(self.model.rowCount()):
if self.model.item(index).checkState():
slid = QSlider(Qt.Horizontal)
sl_val_lbl = QLabel("--")
sl_val_lbl.setMaximumWidth(150) #(a)
#sl_val_lbl.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding) #(b)
sl_name_lbl = QLabel(self.model.item(index).text())
#sl_name_lbl.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)
self.sliders.addWidget(slid,index,0)
slid.setMaximumWidth(200)
self.sliders.addWidget(sl_val_lbl,index,1)
self.sliders.addWidget(sl_name_lbl,index,2)
self.sliders_dict[sl_name_lbl.text()] = (slid,sl_val_lbl,sl_name_lbl)
Now, the issue I have is that some of the values the label takes, are actually pretty long strings.
My first solution was (a), i.e. set a certain size for the label. Of course, this may or may not work depending on the actual size of the text to be rendered, and when said text is only few chars long as in the case with floats, this is not a very clean solution.
I then went on trying (b), i.e. setting the expanding policy of the Qlabel to Expanding. This works fine for the label itself, however it goes to overlap with the next Qlabel in the Layout (column 2), covering its value.
In other words, I was expecting the underlying layout structure to stretch with the contained Widgets, which is not happening.
How to obtain the desired effect of having the size of the column in the layout to follow/adapt to that of the contained widgets?

Related

How to set the length of a tkinter Scale widget to an existing value

tkinter seems to only want to accept an integer for the 'to=number' parameter.
I'm trying to set this parameter to be equal to an existing value, in this case it's the number of instances of an object in a list.
What I tried:
inventory=['coin','coin','coin','torch','coin']
scale=tkinter.Scale(self, orient='horizontal', from_=1, to=inventory.count('coin'))
scale.pack()
What I would want here is for the scale to give me a slider that lets the user choose between one and four, or one and however many coins are in the list. But it outputs a scale that has one on the left side and zero on the right.

restrict table dimensions to the table placeholder dimensions in python-pptx

i am trying to add a table to a presentation using python-pptx with a specific dimensions
i created a slide layout from power-point which contains the table placeholder in the area i want and loaded it using python-pptx.
slide_layout
but regardless of the placeholder dimensions, the table itself after creation is exceeding the placeholder are.
mainly it is dependent on the number of rows as per the documentation "The table's height is determined by the number of rows."
shape_id, name, height = self.shape_id, self.name, Emu(rows * 370840)
i tried to update the placeholder.py file manually and change the row height but the same output appears.
shape_id, name, height = self.shape_id, self.name, Emu(rows * 18429)
the table is insisting on exceeding the placeholder area as per the below image
output
below is my code, any clues ?
from pptx import Presentation
# the presentation including the table placeholder
prs = Presentation('Presentation2.pptx')
slide1 = prs.slides.add_slide(prs.slide_layouts[11])
table_placeholder = slide1.shapes[0]
shape = table_placeholder.insert_table(rows=22,cols=2)
prs.save('test.pptx')
Tables in PowerPoint expand vertically to accommodate new rows; that's just the way they work. You will need to do any resizing yourself, which you may find is a challenging problem. This isn't the same kind of problem when a user is creating a table in the application because they will just make adjustments for fit until it looks best for their purposes.
You'll need to adjust font-size and row-height and perhaps other attributes like column-width etc. based on your application and whatever heuristics you can resolve, perhaps related to the row count and length of text in certain cells and so on.
A table placeholder really just gives a starting position and width.

Singularitygs layout in layout padding

I am using a main layout of two grid-spans, that serve as a content and the right panel. Then, in content, I have three grid-spans, that are equal columns. Like this:
1. Parent span: 6 and 6
2. Child span of first column: 4 and 4 and 4
What happens, is that when I use grid-span for the content 3 columns, then they have paddings, all three of them, and the padding of the last column visually adds to the padding of the parent container to create a double gutter.
However, when I use float-span, then we the last of the three content columns does not have a padding, and looks visually longer than the first two columns.
Is there a way to make all 3 child columns same size, AND have the third column without padding, without having to hack into singularitygs with css overrides?
That's how Singularity's fixed gutters work in the first place.
To apply backgrounds to columns without including their padding, use subcontainers.
See this demo: http://sassmeister.com/gist/b2d957171427022de7c7
PS Don't nest your Sass code. Use semantic classes to address elements directly. Use two-level depth to position children within parents, e. g.:
.parent
.child-1
+grid-span(1,1)
.child-1
+grid-span(1,2)
Never use three-level depth, unless you've got a really-really good reason.

Text alignment in Crystal Reports

I am developing a crystal report and data is also coming fine but I am unable to format the fields in the same, just like a comment field must be multiline but when I select the "can Grow" in Format object section, the display is vague.
Can Grow with a value zero stands for the display will grow to multiple lines till it is displayed fully.
As the grow can happen multiple lines, you can adjust the width of the item so that it will not overlap with other item.
What should You do:
Set can grow property to zero
Resize the item (for which you set cangrow 0) so that it will not overlap the item of the next column.

Setting Color for Category Lines

I have a view that displays data from several categories, where the category (bug severity in my case) is color-coded into the background color of individual entries. Now I'd like to apply the same background color to the category line itself.
As the column setting the background color for the rest of the line isn't displayed in category rows, the setting isn't applied. Is there a workaround for that?
Taken from: http://www-10.lotus.com/ldd/nd6forum.nsf/0/2765b9380021c666852572d800589f9d?OpenDocument
Here is an awkward method that works to color your category rows
differently.
Put a column before all the categorized columns. This will be your color column. Check the Use Value as Color property of the column
properties.
Use one of the functions below:
#If(#IsCategory("any")="any";any;1:1:1)
#If(#IsCategory("x")="y";z;1:1:1)
Note: in the function above, where the word "any" appears, or "x" "y"
and "z", it can be anything, matching or not. It will always evaluate
to false. If you try just #IsCategory, it will error out because that
doesn't return true. And no match you try will ever cause a true
comparison.
That said, the result is that all rows will be colored black if they
are not categories. This overrides the default text color. If you want
another color than black, then adjust the 1:1:1 accordingly
(red:green:blue up to 255 for each position, red= 255:0:0)
Now go to any column and set the text color to the row you want your
categorized rows to appear in, and click Apply to All. Voila!
I was trying to figure out how to do this programmatically and then I wondered, why not just borrow from the mail template? I'd like to suggest you check into how the ColorProfile is used there to allow users to change their color preferences based on a field value (sender name) and see if it can be done for your case.
Or, have them either access the view via a browser client or XPages in the Notes client and assign a class to that dependent on the severity.
You could build the category column formula with HTML such that when it is severe the value is "<tr class='severe'><td>CategoryNameValueHere</td></tr>" or something along those lines, right?

Resources