How to set a content size of UIScrollView using stroyboard(!)? - objective-c

How to set a content size of UIScrollView using stroyboard(!) ?
I have a lot of scrollviews, so I don't want to set size of evry one programmaly

You can use IB settings for this.
Click on the UIScrollView you want to set the content size
Go to the identity inspector in the utilities pane on the right of interface builder
Under "User defined runtime attributes
Click on the + button to add a new keyPath
For keyPath column type in contentSize
For type column change it to size
For value column change it to your desired content size value. e.g.: for a width of 320 and height of 600, write { 320, 600 }
Edit:
Here is a screen shot of it in Xcode 5
http://i41.photobucket.com/albums/e282/RobBob3/ScreenShot2014-02-15at94908PM.png

Related

How do I resize an array of squished PyQt5 widgets? [duplicate]

I have a QScrollArea Widget, which starts empty;
It has a vertical layout, with a QGridLayout, and a vertical spacer to keep it at the top, and prevent it from stretching over the whole scroll area;
Elsewhere in the program, there is a QTextEdit, which when changed, has its contents scanned for "species" elements, and then they are added to the QGridLayout. Any species elements which have been removed are removed too. This bit works;
I have turned the vertical scrollbar on all the time, so that when it appears it does not sit on top of the other stuff in there. Note that the scroll bar is larger than the scroll box already though, despite not needing to be.
This is the problem. The scroll area seems to be preset, and i cannot change it. If i add more rows to the QGridLayout, the scroll area doesn't increase in size.
Instead, it stays the same size, and squeezes the QGridLayout, making it look ugly (at first);
And then after adding even more it becomes unusable;
Note that again, the scroll bar is still the same size as in previous images. The first two images are from Qt Designer, the subsequent 3 are from the program running.
If I resize the window so that the QScrollArea grows, then I see this:
Indicating that there's some layout inside the scroll area that is not resizing properly.
My question is; what do I need to do to make the scrollable area of the widget resize dynamically as I add and remove from the QGridLayout?
If you're coming here from Google and not having luck with the accepted answer, that's because you're missing the other secret invocation: QScrollArea::setWidget. You must create and explicitly identify a single widget which is to be scrolled. It's not enough to just add the item as a child! Adding multiple items directly to the ScrollArea will also not work.
This script demonstrates a simple working example of QScrollArea:
from PySide.QtGui import *
app = QApplication([])
scroll = QScrollArea()
scroll.setWidgetResizable(True) # CRITICAL
inner = QFrame(scroll)
inner.setLayout(QVBoxLayout())
scroll.setWidget(inner) # CRITICAL
for i in range(40):
b = QPushButton(inner)
b.setText(str(i))
inner.layout().addWidget(b)
scroll.show()
app.exec_()
The documentation provide an answer :
widgetResizable : bool
This property holds whether the scroll area should resize the view widget.
If this property is set to false (the default), the scroll area honors the size of its widget.
Set it to true.
Why don't you use a QListView for your rows, it will manage all the issues for you? Just make sure that after you add it you click on the Class (top right window of designer) and assign a layout or it wont expand properly.
I use a QLIstWidget inside a QScrollArea to make a scrollable image list
Try this for adding other objects to the list, this is how I add an image to the list.
QImage& qim = myclass.getQTImage();
QImage iconImage = copyImageToSquareRegion(qim, ui->display_image->palette().color(QWidget::backgroundRole()));
QListWidgetItem* pItem = new QListWidgetItem(QIcon(QPixmap::fromImage(iconImage)), NULL);
pItem->setData(Qt::UserRole, "thumb" + QString::number(ui->ImageThumbList->count())); // probably not necessary for you
QString strTooltip = "a tooltip"
pItem->setToolTip(strTooltip);
ui->ImageThumbList->addItem(pItem);
Update on Artfunkel's answer:
Here's a PySide6 demo that uses a "Populate" button to run the for loop adding items to the scroll area. Each button will also delete itself when clicked.
from PySide6.QtWidgets import *
app = QApplication([])
scroll = QScrollArea()
scroll.setWidgetResizable(True) # CRITICAL
inner = QFrame(scroll)
inner.setLayout(QVBoxLayout())
scroll.setWidget(inner) # CRITICAL
def on_remove_widget(button):
button.deleteLater()
def populate():
for i in range(40):
b = QPushButton(inner)
b.setText(str(i))
b.clicked.connect(b.deleteLater)
inner.layout().addWidget(b)
b = QPushButton(inner)
b.setText("Populate")
b.clicked.connect(populate)
inner.layout().addWidget(b)
scroll.show()
app.exec()

Fit to frame with vertical justification options

Working with InDesign script I am using
TF.fit(FitOptions.frameToContent). //TF as a textFrame
to fit the content into the textframe and remove the extra space
But when I have a condition for vertical justification options set to Align: Bottom i am not able to fit the content.
Assuming this to be my TextFrame (Image 1)
Here are the properties of the text frame (Image 2)
When I do FitOptions.frameToContent i get this (Image 3)
But when the text frame has the align property set to the bottom I want this to fit it like this(this was achieved by double-clicking on the top center alignment as shown in the red indicator below. (Image 4) (Image 5)
I tried all the available options at http://jongware.mit.edu/idcs4js/pe_FitOptions.html but I had no luck making it work. Please help me to achieve the same using scripting.
Cross-reference: https://community.adobe.com/t5/indesign/fit-to-frame-with-vertical-justification-options/td-p/11120458?page=1
================== First try ==================
var tf = app.selection[0];
var tfp = tf.textFramePreferences;
tfp.autoSizingReferencePoint = AutoSizingReferenceEnum.BOTTOM_CENTER_POINT;
tfp.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
tf.fit(FitOptions.frameToContent)
This still gives me the same result(image 3) but expected result is image 4.
================== Second try ==================
This is the auto-sizing property.
This command indeed seems to work only with the top edge as a reference point, just as it does in the UI (if you actually use the menu command, not clicking any borders).
What you could do to work around this, is to temporarily enable auto-sizing (height only) and setting the reference point for auto-sizing to the bottom:
var tf = app.selection[0];
var tfp = tf.textFramePreferences;
tfp.autoSizingReferencePoint = AutoSizingReferenceEnum.BOTTOM_CENTER_POINT;
tfp.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
tfp.autoSizingType = AutoSizingTypeEnum.OFF;
Note, the last line turns off the auto sizing again and is optional; if you don't mind that the frame keeps auto sizing you don't need to turn it off.

Get new Height and Width of Widget after manual resize

After a make a manual resize of my widget using
gridster.resize_widget ( _widget_container , size_x , size_y);
I need to get the new widget size, but I get always the old height. I need to wait a few miliseconds to get the correct new height and width.
There is any way to get an event when Grister has complete the resize widget?
In current version of gridster you can add a callback function to resize widget:
.resize_widget( $widget, [size_x], [size_y], [reposition], [callback] )
You can read details in the gridster page.

There is a section in size inspector with name Autosizing. How to do it from code in OS X?

There is a section in size inspector with name Atosizing that can set left,right,up,down layout of a control,how can i do it from code ?
In the NSView API you can set the autoresizing mask with -setAutoresizingMask:.

Widget integrated going out of its own zone

I got a main window (Item) with a 640*480 size.
I integrated a custom widget defined in another qml file, its size is 100*100. This item contains a Pathview that only shows 3 items from a list containing a lot of items.
The thing is that when I add my CustomPathView to my main window at coords (0, 0), the PathView goes to the bottom of my main window, displaying 7/8 items... (?!?)
My CustomPathView.qml file starts with :
Item {
width: 100
height: 100
That's why I really don't understand why it is displaying 8 items...
Did I do something wrong ? Do I have to precise to my CustomPathView that he can't go out of its zone (how ?) ?
Thanks in advance for any help about it !
Just set the clip property to true.