UITextView changing width screws up word wrap - ios4

While writing a UITextView control, I realized that if I change the width (via setFrame) of the view on scale gesture, the word wrap gets screwed up. It becomes prominent on rescaling multiple times.
By screwing up, I mean that the text starts wrapping from a smaller frame/rectangle than the current width of the textview. This is what I am doing on scale gesture:
[textview setFrame:CGRectMake(textview.frame.origin.x, textview.frame.origin.y, textview.frame.size.width * [gestureRecognizer scale], textview.frame.size.height )];
Also, if it helps to debug, I have subclassed the UITextView and set the canBecomeFirstResponder to NO to block the keyboard & menu. Also I have disabled scrolling by setScrollEnable:NO and setEditable:NO

Related

Fit minimal size of a QDockPanel after QLabel content update

I have a QDockWidget with a QGroupBox as the top widget, with QVBoxLayout applied. This contains a QChartView and a QLabel.
The QLabel contains a text composed of several lines of different length.
First, I would like to have the QChartView the same width and height as the QLabel.
Second, as the content of the QLabel is updated by setText(...) in a Slot method, its content changes in height and width. So I would like to update the width and height of the QChartView above it.
For the moment, I only achieved to grow the entire DockPanel to accomodate longer and wider QLabel content, but not to shrink back when this content is narrower and less wide...
I did play with a lot of things, without real success (here a snippet of the Slot method that updates the QLabel content...):
self.fkChartView.hide()
self.pPDetailsLabel.hide()
self.pPDetailsLabel.parent().hide()
self.pPDetailsLabel.setText(self.canvas.grayScottModel.getPearsonPatternDescription(specie=type))
self.pPDetailsLabel.updateGeometry()
self.pPDetailsLabel.parent().updateGeometry()
self.pPDetailsLabel.parent().update()
self.pPDetailsDock.updateGeometry()
self.pPDetailsDock.update()
self.pPDetailsLabel.show()
self.pPDetailsLabel.parent().show()
# print(self.pPDetailsLabel.sizeHint())
self.fkChartView.setMinimumHeight(self.pPDetailsLabel.size().width())
self.fkChartView.setMaximumHeight(self.pPDetailsLabel.size().width())
self.fkChartView.setMinimumWidth(self.pPDetailsLabel.size().width())
self.fkChartView.setMaximumWidth(self.pPDetailsLabel.size().width())
self.fkChartView.updateGeometry()
self.fkChartView.show()
self.fkChartView.updateGeometry()
self.fkChartView.update()
I tried to hide the widgets, so they forget their sizes and/or sizeHint (not sure).
I tried a few updateGeometry() and update() too, but it does not seem to help.
An idea, anyone?
I had it working as intended in the end by doing this in the slot method that updates the content of the QLabel:
self.fkChartView.hide()
self.pPDetailsLabel.setText(self.canvas.grayScottModel.getPearsonPatternDescription(specie=type))
self.pPDetailsLabel.adjustSize()
self.pPDetailsLabel.parent().adjustSize()
# Sets the dimensions of the chart folowing the label width
self.fkChartView.setMinimumHeight(self.pPDetailsLabel.size().width())
self.fkChartView.setMaximumHeight(self.pPDetailsLabel.size().width())
self.fkChartView.setMinimumWidth(self.pPDetailsLabel.size().width())
self.fkChartView.setMaximumWidth(self.pPDetailsLabel.size().width())
self.fkChartView.adjustSize()
self.fkChartView.show()
self.pPDetailsDock.adjustSize()
So I first hide the QChartView, so its dimensions do not interfere,
then all the magic happens thanks to the adjustSize() call. I do this on the QLabel after its content has been updated,
then on its parent (the top QGroupBox in my QDockWidget).
The QChartView still hidden, I force its dimensions,
then show it and
finally adjust the size of the QDockWidget.
It does precisely what I want:
if text is broader, the chart expands but stays square,
if text is narrower, chart shrinks, but stays square.
Total height of the dock adjusts also to fit, without staying the longer and longer it had to be to accomodate for a big former QLabel content.

vim on iterm cannot open as full screen

I wonder about this bottom and left gap, and also wanna remove it
It occurs only when i open "vim", not Iterm itself
Is there any solution?
The general principle is that the screen of a terminal emulator is a grid where each cell has the same dimensions as the others and those dimensions are determined by the font and font size used. If the window's dimensions and the grid's dimension are incompatible, then the window can't be filled with the grid and you have that kind of gap.
In this case, the cell dimensions are 16px * 38px so the grid can only fit in a box whose dimensions are a multiple of 16 in width and a multiple of 38 in height.
Now, your screen's dimensions appear to be 1630px * 2862px, which is rather unusual. The width is not a multiple of 16 and the height is not a multiple of 38, so, with your current font settings it is impossible to fill the screen.
For that to be theoretically possible, you would need font settings that make individual cells 16.3px wide and 38.16px tall, or some other "impossible" ratio.
Note that you also have a padding, here, that effectively prevents the grid to ever fill the window anyway.
None of that is really a problem when the program you run in your terminal emulator doesn't paint the background of those cells but your Vim colorscheme does, which makes the effect described above apparent.
The only practical workarounds are:
Define the same background in Vim and in your terminal emulator.
Make Vim's background transparent.

PyQt - Keeping spacing at zero during window resize, grid layout

I'm making an emacs-esque toy text editor. At startup, there's one large window (a QTextEdit derivative) in the top center of the screen, with a minibuffer (QLineEdit derivative) underneath. Both of the actual editing widgets are contained in the grids of parent classes called Window and MiniWindow (Window also keeps track of a QLabel that appears directly beneath the QTextEdit).
My Window object is at location 1, 1 in the grid, and my MiniWindow object is at 2, 1. I've set content margins to 0 and spacing to 0, which looks great at first, but when I try to grow the window by dragging on the corner, this starts to happen:
As you can see, the screen is divided into two rows (as it should be), but half of the vertical length of the screen is dedicated to each row. What I need is for the top Window to stretch its length during resizing so that it is always adjacent to the MiniWindow underneath. Is there some other option I need to be setting?
Nevermind, got it.
I was having this problem because the QLineEdit object was in the grid of my container class, MiniWindow. The height of a MiniWindow object is free to vary with the window resizing in a way that a QLineEdit alone would not be. The fix was set to the maximumHeight of MiniWindow to approximately the height of a QLineEdit, which is around 16.
Works great now.

QGridLayout and QVBoxLayout don't auto expand spacing

So if I have two elements in a fixed size window to start with, instead of staying at their layoutVerticalSpacing, the elements auto expand the vertical spaces as I resize the main window.
I've tried self.gridLayout.setVerticalSpacing(0) but that doesn't quite work...
Is there a way to just set the spacing to stay the same no matter what the mainWindow size is?

ScrollPane with preferedViewportWidth matching preferedWidth of content

I have a bunch of regions which have a specific preferedWidth set. These Regions are reused visual components in a drag and drop UI.
I want to create a conatainer of these regions and tried to accomplish this with a ScrollPane with an embedded VBox. I want the scrollpane to be wide enough to hold the VBox without horizontal scrolling.
I could figure out the width of the VBox by hand and hardcode the scrollbars width but i would prefere a dynamic solution so that i can style the vbox later. Unfortunately the vbox preferred width is -1 even though its children have a prefered width set.
Also if i try to set the scrollpanes preferedViewportWidth to the width of my regions i get mixed results dependent on the hbarPolicy. If the policy is set to AS_NEEDED the width of the scrollbar is ignored and the scrollbar appears over my regions when it appears.
Any ideas how i get a SrollPane which is wide enough for my regions with and without a vertical scrollbar and possible styling of paddings etc.
Solved my problem by binding the ScrollPane's prefViewportWidthProperty() to the width property of the child.

Resources