How to resize uilabel using content? - autolayout

I'm trying to resize the uilabel using content, I tried in autolayout ios with cgrectmake, but it's not working.
cell.msglabel=[[UILabel alloc] initWithFrame:CGRectMake(10, 100, myLabel.frame.size.width, myLabel.frame.size.height)];
cell.msglabel.lineBreakMode = NSLineBreakByWordWrapping;
[cell.msglabel setFrame:CGRectMake(10, 10, myLabel.frame.size.width, myLabel.frame.size.height)];
cell.msglabel.text=text;
[cell.msglabel updateConstraints];

UILabel is intrinsicContentSize view which you need not to set frame directly when you using auto layout.
Give edge constraints is enough, width/height constraint are not necessary.
eg. left padding and top padding to other views.

Related

Scrollable DataTable with Auto Height

Alloy UI's DataTable provides a scrollable attribute to define x or y scrolling. This has to be used with a combination of a set height or width.
How can I have a table that will adjust to whatever the height/width of the window along with maintaining the scrollable feature?
Alloy UI API allows you to specify height & width in the px or round number.
If you want to specify in the percentage, set the CSS property "width: 100%" for either the DataTable's table tag, or the div that contains the DataTable.
Example,
First, create a datatable.
Add the CSS attribute for width in percentage
*
var dataTable = new Y.DataTable({
id: 'mydata-table',
footerView: Y.FooterView,
scrollable: "xy",
height:'300px').render();
$('#mydata-table').css('width', '80%');
$('#mydata-table').css('height', '40%');
Please refer the link for detail.
Try this code,
it worked for me in mobile as well as desktop.
container.find(".dataTables_scrollBody").css('height', container.height() - 20);
here the container is a <div> where the datatable is placed.

Setting padding and margin to 0 doesn´t work

It´s just a container and i want to put widgets inside and hide them and show them. I don´t want it to have any margins or paddings, and it will be invisible (no border, no background)
I set the QWidget#container to margin:0px, padding:0px through a stylesheet.
And setObjectName("container") to all the widgets that contain.
Nothing happens. But setting a background color works, so it is executed.
In which cases does this happen?
How to fix this?
QWidget does not support box model, so it does not understand padding/margin CSS directives. Use QFrame as container. To see which widgets support box model take a look at list of stylable widgets
Given there was no concise answer I'll sum up the above:
To create a container with no margins and padding, instead of QWidget, use QFrame, and set a layout on it. Then set the spacing to 0 and set the content margins to 0 as well on the layout. Using a stylesheet setting padding/margin to 0 will have no effect.
Code:
QFrame* containerFrame = new QFrame();
QVBoxLayout* layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
// add some widgets to the layout
containerFrame->setLayout(layout);

How to get accurate width without horizontal scrollbar?

In Qt, I have created a QGraphicsScene as shown below.
m_scene = new QGraphicsScene(0,0,152,720);
m_view = new QGraphicsView(m_scene);
Now the window is created with horizontal and vertical scrollbars. Since I don’t want to use horizontal scroll bar, it used the code
m_view->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
But at this time, there is no horizontal scrollbar and the width is not 150, it is 140 something. How to get accurate width without horizontal scrollbar?
If you want to get the inner width of your QGraphicsView, you can simply subtract the width of the scrollbar from the total width. This is how I would do it:
int innerWidth = width();
if (verticalScrollBar()) innerWidth -= verticalScrollBar()->width();

Qt: How do i set the height on a Vertical layout?

I'm having trouble using the layout manager system with Qt. This is going to be a Symbian app, so it should resize to different devices.
This is done by using the Layouts.
On the image below I used the Vertical Layout, but I don't understand how I can decide how much each cell should take in width and height.
I want the blue to be a top label background, but I don't want it to be as high as it is now.
Does anyone know how I can do this? (I'm new to Qt :))
You can set the maximum size for a widget by right clicking it and selecting 'Size Constraints'. Under that menu you can find actions that allow you to set the current displayed size as the maximum / minimum size for vertical / horizontal or both directions.
You can also set the numbers by hand by selecting the widget and by setting the number in the 'Property Editor'. They should be under the QWidget properties.
You cannot set the Height of a vertical layout directly, but you can set the height of the widget in which the vertical layout is.
If you want to split your Widgets so that the top widget takes 33.33% of the space, use the Stretch values. Set the top widget to 1 and the bottom widget to 2.

Can I make Grid Layout stretch like an HTML table does?

I have use the mx:Grid layout component to layout some form elements in a manner very similar to an HTML table. However, the result does not stretch out horizontally when you resize the app like an HTML table would. How can I make it do that?
Try setting the width and height of the Grid element to a percentage value.
I'm using a Grid on one of my main applications, and I've set the width/height to 100% and it resizes just fine.
You'll likely need to set the width and height of the rows and items (GridRow and GridItem) as well, depending on how you want the rows/columns to resize.
Edit if you're creating the Grid programmatically (e.g. in a .as file), you'll need to set these values as percentages as follows:
var grid:Grid = new Grid();
grid.percentWidth = 100;
grid.percentHeight = 100;

Resources