Setting the size of an SVG icon in a table cell - user-interface

I'd like to increase the size of an SVG icon that's displayed inside of a PySide/Qt table cell
icon = QtGui.QIcon('icon.svg')
entry = QtGui.QTableWidgetItem()
entry.setIcon(icon)
entry.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
table.setItem(row_index, column_index, entry)
Absolutely nothing I try increases the size of the displayed SVG. It is currently displayed as a very small icon and also seems to ignore the alignment. The QIcon docs say that items can be scaled, so there must be a way.
What am I doing wrong?

You should add table.setIconSize(QSize(w, h) (if you use QTableWidget) and entry.setSizeHint(QSize(w, h), docs here, like so:
table.setIconSize(QSize(50, 50))
icon = QtGui.QIcon('icon.svg')
entry = QtGui.QTableWidgetItem()
entry.setSizeHint(QSize(50, 50))
entry.setIcon(icon)
entry.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
table.setItem(row_index, column_index, entry)
The alignment cannot be changed I'm afraid (maybe is doable customizing QTableWidget class). If alignment is a must maybe you can use QTableWidget.setCellWidget(), see this answer.

Related

How to align legend dynamically on top-center of the chart in c3.js?

I want to put the same legend top center of the chart. Legend items will be dynamic, likes sometimes 2,5 or 9, etc.
So, it should take space dynamically like how it is acting on the bottom.
I tried with inset functionality but it seems this is not looking better like the bottom one.
and there are few more complexity like I want it like a flat, so now if I define step size 3 then maybe, for now, it looks good for 9 items. but when there will be 2 items, it will show as a list!!
Although I solved that problem through the following solution:
// get parent elements
let parentEle = d3.selectAll("#chartID svg");
let childrenEle = parentEle
//Convert selection to selection representing the children
.selectAll(function () { return this.childNodes; })
.filter('g');
// putting legends position on TOP
d3.select(childrenEle._groups[0][2]).attr('transform', 'translate(0, 5)');
you have to keep eye on chart width - height and according to this, you may have to control padding in TOP for the chart.
might be this is not a good solution but it works fine for me :D

Change height of figures in GEF programmatically

I have a case where I have to add figures in another figure, i.e., nested figures.
My figure which will contain other figure extends org.eclipse.draw2d.Figure.
I want to change the height of this figure when it contains more than 4 figures, so that all the nested figures are visible at once.
So, in the paintFigure(Graphics graphics) method, I do this:
Rectangle r = getBounds();
if( getChildren().size() > 4 ) {
setBounds(new Rectangle(r.x, r.y, r.width, r.height + getChildren().size()-4)*10));
}
But this doesn't change the height. Well it does change it, for the time being, but when it is called again the next time, it again has the previous height, not the updated one.
Hence, visually the figure height doesn't change at all.
Any ideas on what am I doing wrong?
Or to do this in a different and/or better way?
I was updating the height in the paintFigure(), it was changing to previous height because it was taking values from the model. I changed the height in the model, and it worked fine.

How to arrange views vertically with scrollbar in VisualWorks?

I write RSSReader in Smalltalk so I have two Model classes: RSSModel (title, entries) and EntryModel (title, image, content, date)
I have list of EntryView (inherits from UI.View) now I have RSSView and my displayOn method is going to display entries vertically with gap between each:
| dy iView gap |
gap := 5.
dy := 0.
1 to: model entries size
do:
[:i |
iView := EntryView model: (model entries at: i).
iView displayOn: aGC at: 0 # dy.
dy := dy + 89 + gap]
and the result is:
I am not sure if I do it right way so If you have better solution for display RSSView please tell me.
Questions:
How to get height of entry? Now I write dy:=dy+89+gap where 89 is hardcoded height of entry.
How to enable scrollbars to scroll entries in window?
How to get the height of the entry? Use:
"entry bounds height"
How to enable scrollbars?
To answer this, I'll first point out that the way you're getting the EntryView's displayed isn't really the best way. You want to create a custom control like I explained in your other question How to create a window in smalltalk. You can use a CompositeView for the view and add each of the EntryViews into the composite using add:at:.
Once you have that, you can go to the Details tab in the UIPainter property editor of the view and turn on Vertical scroll bars.

When I am trying to align fields vertically, they aren't behaving what I expected?(Blackberry JDE4.5.0 eclipse)

I am using Eclipse & JDE 4.5.0 plug-in. How to align fields vertically. Can we align fields like LEFT_BOTTOM,RIGHT_BOTTOM, LEFT_VCENTER, RIGHT_VCENTER, CENTER(vertically & horizontally), BOTTOM_CENTER, etc...?
BlackBerry UI field managers are notoriously annoying when dealing with field alignment. Managers seem to ignore all style flags (like HCENTER, VCENTER, etc) so the only way you'll be able to do this is to override the sublayout method of your manager and do it yourself.
Here's a little snippet to show you what I mean. This particular code actually does horizontal centering, not vertical centering, but once you get the idea you can implement any styles you need.
VerticalFieldManager mainmanager = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT)
{
protected void sublayout( int width, int height ) {
super.sublayout( width, height );
width = getWidth();
height = getHeight();
for (int i = 0;i < this.getFieldCount() - 1; i++)
{
Field field = this.getField(i);
//this positions the item in the middle of the manager
int x = (int)((width - field.getWidth()) * 0.50);
setPositionChild(field, x, field.getTop());
}
}
Please note that the USE_ALL_WIDTH and USE_ALL_HEIGHT style flags are important. If you want to do things like vertical centering, bottom-right aligning, etc. you will need to write the positioning code yourself. For bottom-right alignment for example you could set the x position to the width of the manager minus the width of the field, and the y position to the height of the manager minus the height of the field.
If you want to be able to use one custom manager class to handle multiple different styles (like bottom right, bottom left) you can add some logic in sublayout to check the field's style flag and then position the field appropriately.
Hopefully this all makes sense and helps you. :)
HorizontalFieldManager only accepts Vertical Alignment Styles and VerticalFieldManager only accept Horizontal Alignment. That's it.
Annoying ++

How to keep the last tree item of NSOutlineView in the most bottom of a Sidebar?

I'd like to have the same behavior of special items as it's done in the Things application. I mean Logbook and Trash items in the bottom part of the Sidebar:
Logbook and Trash items are in the most bottom http://tinyurl.com/lhctza
Please advise any way to implement the same functionality in the sidebar tree.
I feel that special ‘spacer’ tree item should be used together with outlineView:heightOfRowByItem: method.
However, I can't find how to calculate the total height of all visible items (incl. space between groups).
You might try simply having two outline views: One of fixed height, pinned to the bottom of their superview, and the other of variable height, with its bottom immediately above the top of the first. The fixed-height outline view would contain those Logbook and Trash items, and the variable-height outline view would contain all the others.
The tricky part would be making this play nice with a scroll view, but I think you could do it. I imagine you'd put them both in a fully-resizable NSView and make that the scroll view's document view.
I've decided to hardcode the solution by adding 8 pixels of height for every root item in group style.
So, the code looks like this:
- (CGFloat)outlineView:(NSOutlineView *)ov heightOfRowByItem:(id)item;
{
if (![item isSpacer]) return [ov rowHeight];
static const CGFloat ADDITIONAL_SPACE = 8.0f;
NSUInteger numberOfRootGroups = 2;
CGFloat heightOfRows = [ov rowHeight] * ([ov rowForItem:item] + 1)
+ ADDITIONAL_SPACE * numberOfRootGroups;
CGFloat heightOfSidebar = [[ov superview] frame].size.height;
return MAX(0.0f, heightOfSidebar - heightOfRows);
}
Thanks to everybody for support!

Resources