QGridLayout and QVBoxLayout don't auto expand spacing - pyqt4

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?

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.

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.

PyQt expand scrollarea fully when window is big enough

I'm making a small PyQt gui software for some scripts I often use. Part of this gui has a list of buttons to the right, and the amount of buttons can vary from each run of the gui. For that reason I would like to have them in a scrollarea. This works sort of OK, but for some reason the scroll area will not expand the very last bit when the window size permits it (so no scroller would be shown).
It behaves as if a maximumheight has been set elsewhere, even if I set a maximumheight much higher than the window size?!?
If I set the minimumheight to more than widgetsize, the scroller is hidden as expected, but not if minimumsize is smaller so scroller will be used when window is smaller.
Cutout, left with minimumheight of 550, and right with minimumheight of 200
self.Pvbox = QtGui.QVBoxLayout()
self.syncButton=QtGui.QPushButton('Sync')
self.syncButton.setMaximumWidth(100)
self.Pvbox.addWidget(self.syncButton)
PbuttonWdg = QtGui.QWidget()
Pbuttonlayout = QtGui.QVBoxLayout()
self.nbuttons=[]
c=0
for n in main.Pnames:
self.nbuttons.append(QtGui.QPushButton(str(n)))
self.nbuttons[-1].setMaximumWidth(80)
Pbuttonlayout.addWidget(self.nbuttons[-1])
c+=1
PbuttonWdg.setLayout(Pbuttonlayout)
scroll=QtGui.QScrollArea()
scroll.setMaximumWidth(110)
scroll.setMinimumWidth(110)
scroll.setMinimumHeight(550)
scroll.setMaximumHeight(800)
scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
scroll.setWidgetResizable(False)
scroll.setWidget(PbuttonWdg)
self.Pvbox.addWidget(scroll)
self.Pvbox.addStretch(1)
self.localButton=QtGui.QPushButton('Local')
self.localButton.setMaximumWidth(100)
self.Pvbox.addWidget(self.localButton)
Found the problem...
The "addStretch(1)" after the scrollarea, makes that stretch part start to stretch before the scrollarea is fully expanded for some reason. Removing that stretcher makes the scrollarea do all the expanding/stretching (if the sizepolicy permits).
So I consider this as a solution, eventhough the optimal for me would be that the scrollarea would expand fully before any stretch takes over...

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.

UITextView changing width screws up word wrap

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

Resources