qlayout

Pyqt5 addStretch in between widgets?

柔情痞子 提交于 2019-12-11 14:14:20
问题 I am using a QVBox layout and there are two widgets and a dynamic layout 'layout2' in the layout. Widget1 is fixed on top Widget3 is fixed at the bottom and widget2 is dynamic widget. layout2 is deleted and added each time. The problem here is I am not able to position the widget3 at the bottom as layout2 layout is deleted Widget3 moves to the top. Below is the sample code. class Screen(QWidget): def __init__(self): super(Screen, self).__init__() self.main_layout = QVBoxLayout() widget1 =

Why is the QScrollArea restricted in size?

血红的双手。 提交于 2019-12-11 14:07:45
问题 To my custom widget, inherited from QWidget , I have added a QScrollArea like this: MainWindow::MainWindow(QWidget *parent) : QWidget(parent)//MainWindow is a QWidget { auto *scrollArea = new QScrollArea(this); auto *widget = new QWidget(this); widget->setStyleSheet("background-color:green"); scrollArea->setWidget(widget); scrollArea->setWidgetResizable(true); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); QVBoxLayout *parentLayout = new QVBoxLayout(widget); this-

Qt: HBoxLayout - stop MainWindow from resizing to contents

这一生的挚爱 提交于 2019-12-11 10:03:36
问题 It seems most people are asking how to make their QMainWindow resize to its contents - I have the opposite problem, my MainWindow does resize and I don't know why. When I set my QLabel to a longer text, my mainwindow suddenly gets bigger, and I can't find out why that happens. The following example code basically contains: A QMainWindow A QWidget as central widget A QVBoxLayout as a child of that A LabelBar inside that. The LabelBar is a QWidget which in turn contains: A QHBoxLayout Two

QWebView set border visible

China☆狼群 提交于 2019-12-11 02:35:30
问题 I want to make QWebView widget have borders in my layout and UI when running, similar to QTableView . Now it looks borderless and hidden. Is it even possible? 回答1: It's not possible to set border to QWebView. Instead you can place your QWebView inside another QWidget and set it's border. See example below (QtDesigner): Widgets hierarchy: Look inside QtDesigner: StyleSheet for QFrame: QFrame { border: 1px solid black; background: white; } 来源: https://stackoverflow.com/questions/21249403

Align every widget of a QHBoxLayout to the top

空扰寡人 提交于 2019-12-10 20:04:01
问题 I'm trying to align every widgets in a QHBoxlayout to the top but what I get is every widget seems centered. I think this is due to there different sizes. For instance with: from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * import sys class SurfViewer(QMainWindow): def __init__(self, parent=None): super(SurfViewer, self).__init__() self.parent = parent self.setFixedWidth(300) self.setFixedHeight(100) self.wid = QWidget() self.setCentralWidget(self.wid) self

How to programatically resize a QMainWindow to its minimum size

时光毁灭记忆、已成空白 提交于 2019-12-10 14:04:56
问题 When I have a QMainWindow with a grid layout, when resizing it with the mouse, it won't go below some minimum size that's necessary for all the controls in it to show properly. In my app I sometimes programatically hide controls, but then the window remains the same size and the rest of the controls look spread out, with too much space between them. I end up resizing the dialog manually so it doesn't look ugly. Can I programatically set the dialog's vertical size to this minimum I get when

How to align the layouts QHBoxLayout and QVBoxLayout?

…衆ロ難τιáo~ 提交于 2019-12-10 10:37:32
问题 I want to do this layout for my window: So I tried to create a QHBoxLayout layout to put the 3 buttons, and add it to the QVBoxLayout : #!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): title = QtGui.QLabel( 'Title' ) author = QtGui.QLabel( 'Author' ) other = QtGui.QLabel( 'Other' ) titleEdit = QtGui.QLineEdit() horizontalLayout = QtGui.QHBoxLayout( self

QGridLayout, 3 panes, not expanding properly

自古美人都是妖i 提交于 2019-12-07 01:58:31
问题 I'm trying to layout a window (all in code) with a QGridLayout . I can add widgets to the layout and they display in my window, but I can't figure out how to resize them properly. Here's what I'd like [Leftmost][--------Center---------][Rightmost] Those are the 3 "panes" of my window (all three of them lists). The left and right ones should be of a static width and hug their respective sides, and the center should expand to fill the width as the window grows (or shrinks). Some code: // Create

PyQt5 - Add image in background of MainWindow layout

Deadly 提交于 2019-12-06 14:27:36
问题 New to PyQt5... Here is a very basic question. I would like to add an image inside the layout of a widget. This widget is the Main Window / root widget of my application. I use the following code, but I get an error message. import sys from PyQt5.QtGui import QImage from PyQt5.QtWidgets import * class MainWindow(QWidget): def __init__(self): super().__init__() self.setGeometry(300,300,300,220) self.setWindowTitle("Hello !") oImage = QImage("backgound.png") oLayout = QVBoxLayout() oLayout

How to align the layouts QHBoxLayout and QVBoxLayout?

*爱你&永不变心* 提交于 2019-12-06 08:28:29
I want to do this layout for my window: So I tried to create a QHBoxLayout layout to put the 3 buttons, and add it to the QVBoxLayout : #!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): title = QtGui.QLabel( 'Title' ) author = QtGui.QLabel( 'Author' ) other = QtGui.QLabel( 'Other' ) titleEdit = QtGui.QLineEdit() horizontalLayout = QtGui.QHBoxLayout( self ) horizontalLayout.addWidget( title ) horizontalLayout.addWidget( author ) horizontalLayout.addWidget(