How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered

How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered

By : user3100406
Date : January 12 2021, 07:00 PM
hope this fix your issue I want to create a dialog, in which the user should first select one item in a drop down, and for some choices specify an additional parameter. For the sake of the example let's say that the possible choices are A and B and for B the user has to enter a text. The text field should not be visible when A is selected. , You could try something like this:
code :
def __init__(self, parent=None) :
    super(QDialog, self).__init__(parent)
    self.mainLayout = QGridLayout()

    self.label = QLabel('label')
    self.mainLayout.addWidget(self.label, 0, 0)
    self.comboBox = QComboBox()
    self.comboBox.addItems(['A', 'B'])
    self.mainLayout.addWidget(self.comboBox, 0, 1)
    self.lineEdit = QLineEdit('', self)
    self.mainLayout.addWidget(self.lineEdit, 0, 2)



Share : facebook icon twitter icon
How to prevent widget's size changing in Kivy?

How to prevent widget's size changing in Kivy?

By : Edgar Alberto Ramos
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further (100, 100) is the default size for widgets. In this case your painter has that size because you never set it to anything else.
Even if its parent were a layout class that would automatically move and resize the painter, its size would still read (100, 100) at this point because the layout hasn't had time to run yet. You shouldn't generally worry about the pixel values at this point - if you need something else to depend on them, use a binding to update the other thing automatically when the first one changes. This is made particularly easy by kv language.
When will widgets update after widget visibility change in Qt?

When will widgets update after widget visibility change in Qt?

By : Rui Ong
Date : March 29 2020, 07:55 AM
Does that help I want to change visibility of two widgets one by one. In my case, i need to do some process then sleep 1s and change visibility of WidgetA. And sleep 1s chnage visibility of WidgetB. This is my code.
code :
void MainWindow::Initialize()
    WidgetA->installEventFilter( this );
    WidgetA->setVisible( true );

bool MainWindow::eventFilter( QObject *object, QEvent *event )
    if( object == WidgetA )
        if( event->type() == QEvent::Show )
            WidgetB->setVisible( true );
    return QMainWindow::eventFilter( object, event );
PyQt5: main window shows without any widgets

PyQt5: main window shows without any widgets

By : Florian Pahl
Date : March 29 2020, 07:55 AM
This might help you I'm using PyQt5 to create my application. The problem is that my window appears, but without any widgets (i.e. without my Main class, without any menus, toolbars, etc.) - just still empty. I'm using Python-3.6 and PyQt5, Windows 10 environment. , To fix your example, use this Main class:
code :
class Main(QWidget):
    def __init__(self, *args):
        QWidget.__init__(self, *args)

        familyTreeView = FamilyTreeView(self)
        eventsTableView = EventsTableView(self)

        HSplitter = QSplitter(Qt.Horizontal)

        HSplitter.setStretchFactor(1, 1)

        grid = QGridLayout()
class TerraSoft(QMainWindow):
    def __init__(self):

        exitAct = QAction(QIcon('exit24.png'), 'Exit', self)

        fileMenu = self.menuBar().addMenu('File')

        toolbar = self.addToolBar('Main')

        main = Main()

        self.statusBar().showMessage('Bienvenue dans TerraSoft')
class FamilyTreeView(QTreeView):
    def __init__(self, *args):
        QTreeView.__init__(self, *args)
        self.addItems(self.model(), families)

    def addItems(self, parent, elements):
        for text, children in elements:
            item = QStandardItem(text)
            if children:
                self.addItems(item, children)
class EventsTableView(QTableWidget):
    def __init__(self, *args):
        QTableWidget.__init__(self, *args)
        self.setHorizontalHeaderLabels(('Date', 'Catégorie', 'Description'))
How to change display size changing with window size in PyQT5?

How to change display size changing with window size in PyQT5?

By : user2056877
Date : March 29 2020, 07:55 AM
I hope this helps you . You can listen to the resize event of PlayStreaming and send the adjusted size to the thread through the signal for scaling.
code :
from PyQt5 import QtCore, QtGui, QtWidgets
import cv2

class Thread(QtCore.QThread):
    changePixmap = QtCore.pyqtSignal(QtGui.QImage)
    scaled_size = QtCore.QSize(640, 480)

    def run(self):
        cap = cv2.VideoCapture(0)
        while True:
            ret, frame = cap.read()
            if ret:
                rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                convertToQtFormat = QtGui.QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QtGui.QImage.Format_RGB888)
                p = convertToQtFormat.scaled(self.scaled_size, QtCore.Qt.KeepAspectRatio)

    def scaled(self, scaled_size):
        self.scaled_size = scaled_size

class PlayStreaming(QtWidgets.QLabel):
    reSize = QtCore.pyqtSignal(QtCore.QSize)
    def __init__(self):
        super(PlayStreaming, self).__init__()

    def setImage(self, image):

    def initUI(self):
        # create a label
        self.label = QtWidgets.QLabel(self)
        th = Thread(self)
        lay = QtWidgets.QVBoxLayout(self)
        lay.addWidget(self.label, alignment=QtCore.Qt.AlignCenter)

    def resizeEvent(self, event):

class UIWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(UIWidget, self).__init__(parent)
        # Initialize tab screen
        self.tabs = QtWidgets.QTabWidget()
        self.tab1 = QtWidgets.QWidget()
        self.tab2 = QtWidgets.QWidget()
        self.tab3 = QtWidgets.QWidget()

        # Add tabs
        self.tabs.addTab(self.tab1, "Face")
        self.tabs.addTab(self.tab2, "Human")
        self.tabs.addTab(self.tab3, "Vehicle")

        # Create first tab
        self.tab1.layout = QtWidgets.QVBoxLayout()
        self.display = PlayStreaming()
        self.tab1.layout.addWidget(self.display, stretch=1)

        # Add tabs to widget
        layout = QtWidgets.QVBoxLayout(self)

    def createGridLayout(self):
        self.horizontalGroupBox = QtWidgets.QGroupBox("Control")
        self.horizontalGroupBox.setStyleSheet("QGroupBox { background-color: red}");
        layout = QtWidgets.QGridLayout()
        layout.addWidget(QtWidgets.QPushButton('Test'), 0, 0)
        layout.addWidget(QtWidgets.QPushButton('Run'), 0, 1)
        layout.addWidget(QtWidgets.QPushButton('Set Faces'), 0, 2)
        layout.addWidget(QtWidgets.QPushButton('Recognize'), 1, 0)
        layout.addWidget(QtWidgets.QPushButton('Rescale'), 1, 1)
        layout.addWidget(QtWidgets.QPushButton('FacePose'), 1, 2)

if __name__ == '__main__':
    import sys

    app = QtWidgets.QApplication(sys.argv)
    w = UIWidget()
    w.resize(1000, 800)
How to make widgets scale with the window in PyQt5?

How to make widgets scale with the window in PyQt5?

By : Miguel Oyarzo
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I'm trying to set up a GUI which will include multiple pages in PyQt5. The window will have a minimum size of 800x600, but is customisable beyond that. I want most, but not all, elements on the window to scale along with it. I have a solution already, but I feel that it is not very elegant. , Try it:
code :
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore    import *
from PyQt5.QtGui     import *

class CreatePage(QWidget):
    def __init__(self, parent=None):

    def initUI(self):
        self.homeBtn = QPushButton("Home") 

        self.frontLabel = QLabel("Front") 
        self.frontLabel.setFont(QFont("Decorative", 20))
        self.frontEdit = QTextEdit(placeholderText="frontEdit") 
        self.frontEdit.setFont(QFont("Decorative", 11))

        self.backLabel = QLabel("Back") 
        self.backLabel.setFont(QFont("Decorative", 20))
        self.backEdit = QTextEdit(placeholderText="backEdit") 
        self.backEdit.setFont(QFont("Decorative", 11))

        grid = QGridLayout()
        grid.addWidget(self.homeBtn,    0, 0, alignment=Qt.AlignTop | Qt.AlignLeft)
        grid.addWidget(self.frontLabel, 1, 0, alignment=Qt.AlignCenter)
        grid.addWidget(self.frontEdit,  2, 0)
        grid.addWidget(self.backLabel,  3, 0, alignment=Qt.AlignCenter)
        grid.addWidget(self.backEdit,   4, 0)


if __name__=="__main__":
    app = QApplication(sys.argv)
    myapp = CreatePage()
Related Posts Related Posts :
  • Tuning the hyperparameter with gridsearch results in overfitting
  • some coordinates that I extracted from geocoder in Python are not saving in the variable I created
  • 7C in cs circles- python Im not sure what is wrong with this yet
  • How to fix 'AttributeError: 'list' object has no attribute 'shape'' error in python with Tensorflow / Keras when loading
  • python - thread`s target is a method of an object
  • Retrieve Variable From Class
  • What is the reason for matplotlib for printing labels multiple times?
  • Why would people use ThreadPoolExecutor instead of direct function call?
  • When clear_widgets is called, it doesnt remove screens in ScreenManager
  • Python can't import function
  • Pieces doesn't stack after one loop on my connect4
  • How to change font size of all .docx document with python-docx
  • How to store a word with # in .cfg file
  • How to append dictionaries to a dictionary?
  • How can I scrape text within paragraph tag with some other tags then within the paragraph text?
  • Custom entity ruler with SpaCy did not return a match
  • Logging with two handlers - one to file and one to stderr
  • How to do pivot_table in dask with aggfunc 'min'?
  • This for loop displays only the last entry of the student record
  • How to split a string by a specific pattern in number of characters?
  • Python 3: how to scrape research results from a website using CSFR?
  • Setting the scoring parameter of RandomizedSeachCV to r2
  • How to send alert or message from view.py to template?
  • How to add qml ScatterSeries to existing qml defined ChartView?
  • Django + tox: Apps aren't loaded yet
  • My css and images arent showing in django
  • Probability mass function sum 2 dice roll?
  • Cannot call ubuntu 'ulimit' from python subprocess without using shell option
  • Dataframe Timestamp Filter for new/repeating value
  • Problem with clicking select2 dropdownlist in selenium
  • pandas dataframe masks to write values into new column
  • How to click on item in navigation bar on top of page using selenium python?
  • Add multiple EntityRuler with spaCy (ValueError: 'entity_ruler' already exists in pipeline)
  • error when replacing missing ')' using negative look ahead regex in python
  • Is there a way to remove specific strings from indexes using a for loop?
  • select multiple tags by position in beautifulSoup
  • pytest: getting AttributeError: 'CaptureFixture' object has no attribute 'readouterror' capturing stdout
  • Shipping PyGObject/GTK+ app on Windows with MingW
  • Python script to deduplicate lines in multiple files
  • How to draw stacked bar plot from df.groupby('feature')['label'].value_counts()
  • Python subprocess doesn't work without sleep
  • How can I adjust 'the time' in python with module Re
  • Join original np array with resulting np array in a form of dictionary? multidimensional array? etc?
  • Forcing labels on histograms in each individual graph in a figure
  • For an infinite dataset, is the data used in each epoch the same?
  • Is there a more efficent way to extend a string?
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org