Qt - How to make QTextBrowser resize to contents (vertical layout) - html

I have a QTextBrowser object in my dialog which will have HTML written to it. It is in a vertical layout with several other objects. I have the vertical size policy currently set to MinimumExpanding for this QTextbrowser. The problem is if the HTML written to the browser ends up taller than the QTextBrowser's minimum set height, its height stays the same and it instead makes me scroll down through the browser to see all the data, where I would like it instead to show all the data at once. I have tried changing around the size policies for the QTextBrowser and the layout it is in, but nothing I have tried has worked. Is there a way to do this that I am overlooking?

QTextBrowser *m_text=new QTextBrowser;
m_text->setFixedHeight(m_text->document()->size().height());
wish to help you.

If you know how many lines you are going to add then you can work out a height and then set that height.
int number_of_lines; // If you can get this value from somewhere this should work
// Get the height of the font being used
QFontMetrics font_metrics(ui->text_browser->font());
int font_height = font_metrics.height();
// Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin?
int height = font_height * number_of_lines;
// Set the height to the text broswer
ui->text_browser->setMinimumHeight(height);
ui->text_browser->setMaximumHeight(height);

Related

AS3 : Create a responsive mxml resize bitmapimage which resizes according to browser

I have a simple bitmap image 3px wide and 150px high included as the top banner in my layout.
<s:BitmapImage id="blueBanner" source="{this.bmpimg}" width="100%"/>
The rest of the content is centered below this.
When the page opens no matter the size of the browser window, the image always fills the width available.
I have a browser window resize handler that resets my main content below the banner to the center of the new window size and this works perfectly.
But no matter how many times the browser is resized, the BitmapImage will never stretch wider than the original window width.
I have tried every property and method of BitmapImage that I think could affect this in the resize handler but nothing I can find has any effect at all.
I cannot understand how it remembers the original stage width to begin with.
Its parent containers are all set to 100% width and there are no unusual skins or any other reference to this object in the whole project except in a function where it can be included in the layout or not, but this function is never called in this case.
Can anyone offer any clue as to why it won't stretch automatically?
Doug
Simple , just set the width to screen.width and you are good to go.
<s:BitmapImage id="blueBanner" source="{this.bmpimg}" width="{screen.width}"/>
Thanks for all the responses. In fact I solved the problem by adding the BitmapImage line to the Application Skin. Once it's here as well as in the layout it works. I have no idea why it needs to be in both places, but once it's set up like this everything works correctly.
Setting ScaleMode makes no difference and setting screen.width either in the blueBanner tag or later in the resizeHandler (because not always available when the tag is run) also makes no difference in my layout.
Doug

HTML Image Sizing and Variables

I'm using an application called iDashboards, and in it there is a feature I can add called a ViFrame that takes very limited HTML to create a custom frame.
My knowledge of HTML is already pretty limited and with no output feedback, it's hard to use trial and error as a tactic.
I'm trying to display an image. The image changes dependent on the person that's selected in the app. The selection is taken care of by itself, but the problem is that the size of the pictures vary. I'm trying to display the image so that it has a definite height and a scaled width.
Displays the full size image. The HEIGHT element doesn't seem to constrain anything. If I add a WIDTH tag it works but the scaling would be messed up. Is there any way to do what I want?
The way I see it, I have two options I can think of:
1. Make every image in the library a square and then specify square dimensions so no distortion
2. Somehow retrieve the original height and width into variables in HTML and specify both tags with height being constant and width being an expression of the ratio between height and width. None of which I know is even possible. Is it? I don't think it allows tags either to go into JavaScript.
Sorry about my very basic knowledge in HTML, be gentle.
Are you using one object and changing the image or using many images and changing which one is displayed? Any way you could try to use width:YOUR_VALUE_HERE; height:auto in your css document, which should keep them all in the same ratio.
Set a particular class on the IMG tag:
<img class='constrained_img' src='/path/to/img.png'>
In your CSS/Stylesheet:
.constrained_img {
max-width:100px;
max-height:100px;
}
That should keep your height and width to no larger than 100px in this case. Any further work you'd need to do server-side processing (a la PHP's getimagesize()), or use a 3rd-party library (I've used Joseph Lencioni's SLIR to good effect), or muck around with JavaScript (which isn't impossible, but off the top of my head I'm not sure how I'd go about it).

Need to make Google prettyprint scroll without a max-width

I'm using google prettyprint to display code, the problem is that my code sections will not resize to be scrollable unless I set a max-width on them. But I can't set the max-width to the device width, at least I can't figure out how to do that.
Is there a better way to do this?
The problem is when it shows up on mobile it will be as wide as the longest line of code...

Background colors stop at 100% but not when screen has to scroll to the right. Any ideas how to fix

This is more of a general question; but I notice on some webistes (including stackoverflow) That when content is off the screen and the user has to scroll to the right background images/color stop at 100% of the screen view. Does anyone have a better idea how to fix this.... other than setting max and min widths?
here is a google doc of two different websites to explain what I am talking about.
https://docs.google.com/document/d/133Uek4Fd3G3eB6Zz4CNomPGzARevCUg4fAV4Xhvin-o/edit?usp=sharing
Josh C's response is spot on. If the elements that have background colours had min-widths that matched the content width (980px in stackoverflow's case) then the issue would be resolved. This is not only the easiest way, but probably the best practice)
Your alternative, if you don't want to set max and min values to your elements that use percentages, would be to not set fixed widths on elements (in the case of stack overflow, it's content width is fixed at 980px, and most everything else is fluid).
If content and it's children used max-width instead of width this problem would disappear.
Alternately, as lookingGlass points out, more fluid responsiveness.
Add breakpoints so that when your window size is below/above your ideal the site adapts.

making huge pixel images fit to the given width and height

I got a problem with images and its pixels probem.well let me tell you this.I got a picture of 2448 x 3264 pixels. So its a big image I just decided to reduce its size using this way
<img src="1.jpg" style="width:600px;height:500px"/>
But there is a problem I see, the picture looses its clarity and its visibility, it looks like pulled it close and the person in the images looks so ugly.but using the original size makes look so big . I am sure there is a way to do because I see google images result and also on some websites I tried to see thier code but Could not figure it out.
Could anyone please tell me how do i make the images look good even when they got too long resolution and make them fit in the given width?
Update
Okay now i understand we need some server side image processing and could anyone tell me what would be the way to do it Thanks
The most wide-used practice is to resize the image server-side. When the image is uploaded to the server (e.g. by the user) the server takes it and creates and creates needed thumbnails.
Unfortunately this cannot be done with HTML, CSS nor JavaScript. And there are a lot of cons of forcing the size of the image with CSS. For example the user have to download the whole image ( I guess yous is about 6MB ) and it could take a lot of time .
Withour any language you cant do it, or you have to edit the image and need to upload to your host.
Try using the plain html. It will also help if you have the right width:height ratio (in this case, 3:4)
so:
<img src="1.jpg" width="375" height="500"/>
To gain better quality you need something more, then only HTML. You have to resize images manually, either use some server-side scripting to prepare images before rendering (better even do it on uploading if you sure about specific dimensions).
What you need is server side image processing. For exaple phpThumb or another implementation depending on your serwer platform.
Example:
<img src="../phpThumb.php?src=1.jpg&w=600" />
the phpThumb will open image passed in src, and resize it to width passed in w -> the process image on the fly and outputs to the browser.
For pictures to maintain their clarity, you need to ensure that you maintain aspect ratio. Aspect ratio is the width/height ratio of images and if you resize images maintaining the ratio, then their clarity is maintained. You are getting the resized image to be messed up because 2448/3264 != 600/500.
Now tag resizes by aspect ratio, if you give only one of the attributes of width or height. eg:
<img src="your_src" width=600>
This will render maintaining aspect ratio(it calculates the height needed). However, this could lead to problem sometimes if you have a max-height constraint, because the recalculated height could exceed the div height, if your div has a max-height.
If you have a max-height and max-width constraint, you can use the following code to resize the image using JS. I am assuming that max-width and max-height values as 600px and 500px respectively and you can change as per your needs:
height = this.clientHeight;
width = this.clientWidth;
aspectRatio = width / height;
if (height > width)
{
height = 500;
width = height * aspectRatio;
}
else if (width > height)
{
width = 600;
height = width / aspectRatio;
}
this.setAttribute("height", height+"px");
this.setAttribute("width", width+"px");