Skip to main content

QDialog with QScrollArea adjustSize on widget hide

File: search.py

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '/home/chris/Documents/papinhio-player/ui/menu-3/radio-stations/search/search.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(837, 556)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/main-window/assets/images/main-window/search.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Dialog.setWindowIcon(icon)
        Dialog.setStyleSheet("QScrollArea{\n"
"    border:0px;\n"
"}")
        self.gridLayout = QtWidgets.QGridLayout(Dialog)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.scrollArea = QtWidgets.QScrollArea(Dialog)
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setObjectName("scrollArea")
        self.scrollAreaWidgetContents = QtWidgets.QWidget()
        self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 837, 556))
        self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
        self.verticalLayout.setObjectName("verticalLayout")
        self.search_frame = QtWidgets.QFrame(self.scrollAreaWidgetContents)
        self.search_frame.setStyleSheet("QFrame{\n"
"    border:none;\n"
"}")
        self.search_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.search_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.search_frame.setObjectName("search_frame")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.search_frame)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.search_phrase = QtWidgets.QLineEdit(self.search_frame)
        self.search_phrase.setObjectName("search_phrase")
        self.horizontalLayout.addWidget(self.search_phrase)
        self.search_button = QtWidgets.QPushButton(self.search_frame)
        self.search_button.setIcon(icon)
        self.search_button.setObjectName("search_button")
        self.horizontalLayout.addWidget(self.search_button)
        self.verticalLayout.addWidget(self.search_frame)
        self.loading_frame = QtWidgets.QFrame(self.scrollAreaWidgetContents)
        self.loading_frame.setStyleSheet("QFrame{\n"
"    border:none;\n"
"}")
        self.loading_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.loading_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.loading_frame.setObjectName("loading_frame")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.loading_frame)
        self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        spacerItem = QtWidgets.QSpacerItem(291, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem)
        self.loading_label = QtWidgets.QLabel(self.loading_frame)
        self.loading_label.setMinimumSize(QtCore.QSize(220, 20))
        self.loading_label.setMaximumSize(QtCore.QSize(220, 20))
        self.loading_label.setText("")
        self.loading_label.setObjectName("loading_label")
        self.horizontalLayout_2.addWidget(self.loading_label)
        spacerItem1 = QtWidgets.QSpacerItem(290, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem1)
        self.verticalLayout.addWidget(self.loading_frame)
        self.results_label = QtWidgets.QLabel(self.scrollAreaWidgetContents)
        self.results_label.setStyleSheet("QLabel{\n"
"    font-weight:bold;\n"
"    text-decoration:underline;\n"
"}")
        self.results_label.setAlignment(QtCore.Qt.AlignCenter)
        self.results_label.setObjectName("results_label")
        self.verticalLayout.addWidget(self.results_label)
        self.table = QtWidgets.QTableWidget(self.scrollAreaWidgetContents)
        self.table.setObjectName("table")
        self.table.setColumnCount(3)
        self.table.setRowCount(0)
        item = QtWidgets.QTableWidgetItem()
        self.table.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        self.table.setHorizontalHeaderItem(1, item)
        item = QtWidgets.QTableWidgetItem()
        self.table.setHorizontalHeaderItem(2, item)
        self.table.horizontalHeader().setCascadingSectionResizes(False)
        self.table.horizontalHeader().setDefaultSectionSize(150)
        self.table.horizontalHeader().setStretchLastSection(True)
        self.verticalLayout.addWidget(self.table)
        self.label_2 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
        self.label_2.setStyleSheet("QLabel{\n"
"    font-weight:bold;\n"
"    color:green;\n"
"}")
        self.label_2.setAlignment(QtCore.Qt.AlignJustify|QtCore.Qt.AlignVCenter)
        self.label_2.setWordWrap(True)
        self.label_2.setObjectName("label_2")
        self.verticalLayout.addWidget(self.label_2)
        self.ok = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(":/rest-windows/assets/images/rest-windows/ok.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.ok.setIcon(icon1)
        self.ok.setObjectName("ok")
        self.verticalLayout.addWidget(self.ok)
        self.scrollArea.setWidget(self.scrollAreaWidgetContents)
        self.gridLayout.addWidget(self.scrollArea, 0, 0, 1, 1)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Εύρεση ραδιοφωνικών συνδέσεων"))
        self.search_phrase.setPlaceholderText(_translate("Dialog", "Αναζήτηση βάση τίτλου ραδιοφωνικής σύνδεσης"))
        self.search_button.setText(_translate("Dialog", "Αναζήτηση"))
        self.results_label.setText(_translate("Dialog", "Αποτέλεσμα αναζήτησης: Η αναζήτηση ολοκληρώθηκε επιτυχώς. Βρέθηκαν ... ραδιοφωνικές συνδέσεις"))
        item = self.table.horizontalHeaderItem(0)
        item.setText(_translate("Dialog", "Τίτλος"))
        item = self.table.horizontalHeaderItem(1)
        item.setText(_translate("Dialog", "Radio hostname"))
        item = self.table.horizontalHeaderItem(2)
        item.setText(_translate("Dialog", "Ενέργεια"))
        self.label_2.setText(_translate("Dialog", "Σημείωση 1: Η αναζήτηση πραγματοποιείτε με κριτήριο τον τίτλο των ραδιοφωνικών συνδέσεων.\n"
"Σημείωση 2: Αφήστε κένο πεδίο για εύρεση όλων των ραδιοφωνικών συνδέσεων.\n"
"Σημείωση 3: Η αναζήτηση είναι case insensitive δηλαδή θα πρέπει να δοκιμάσετε και με κεφαλαίους χαρακτήρες εφόσον δεν βρεθούν αποτελέσματα."))
        self.ok.setText(_translate("Dialog", "Εντάξει - Κλείσιμο παραθύρου"))
import sys
sys.path.append('../../../')

#import importlib
#icons = importlib.import_module('compiled-ui.icons')


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

File: search_support.py

from PyQt5 import QtCore, QtGui, QtWidgets
import search
import sys

class Run_me:

    def __init__(self):
        self.app = QtWidgets.QApplication(sys.argv)
        self.Dialog = QtWidgets.QDialog()
        self.ui = search.Ui_Dialog()
        self.ui.setupUi(self.Dialog)
        self.Dialog.show()
        
        
        self.ui.table.setColumnWidth(0, 350)
        self.ui.table.setColumnWidth(1, 120)
        

        
        self.ui.loading_frame.hide()
        self.ui.table.hide()
        self.ui.results_label.hide()
        
        self.Dialog.adjustSize()
        
        
        self.Dialog.hide()
        self.Dialog.show()
        self.Dialog.update()
        


        sys.exit(self.app.exec_())

if __name__ == "__main__":
    programm = Run_me()

Try to run search_support.py

The result is:

enter image description here

but the desired result is:

enter image description here

How can i adjustSize of QDialog which has inside a QScrollArea? Which size policies should i use?

Here is the search.ui file:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>837</width>
    <height>556</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Εύρεση ραδιοφωνικών συνδέσεων</string>
  </property>
  <property name="windowIcon">
   <iconset>
    <normaloff>:/main-window/assets/images/main-window/search.png</normaloff>:/main-window/assets/images/main-window/search.png</iconset>
  </property>
  <property name="styleSheet">
   <string notr="true">QScrollArea{
    border:0px;
}</string>
  </property>
  <layout class="QGridLayout" name="gridLayout">
   <property name="leftMargin">
    <number>0</number>
   </property>
   <property name="topMargin">
    <number>0</number>
   </property>
   <property name="rightMargin">
    <number>0</number>
   </property>
   <property name="bottomMargin">
    <number>0</number>
   </property>
   <item row="0" column="0">
    <widget class="QScrollArea" name="scrollArea">
     <property name="widgetResizable">
      <bool>true</bool>
     </property>
     <widget class="QWidget" name="scrollAreaWidgetContents">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>837</width>
        <height>556</height>
       </rect>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
        <widget class="QFrame" name="search_frame">
         <property name="styleSheet">
          <string notr="true">QFrame{
    border:none;
}</string>
         </property>
         <property name="frameShape">
          <enum>QFrame::StyledPanel</enum>
         </property>
         <property name="frameShadow">
          <enum>QFrame::Raised</enum>
         </property>
         <layout class="QHBoxLayout" name="horizontalLayout">
          <property name="leftMargin">
           <number>0</number>
          </property>
          <property name="topMargin">
           <number>0</number>
          </property>
          <property name="rightMargin">
           <number>0</number>
          </property>
          <property name="bottomMargin">
           <number>0</number>
          </property>
          <item>
           <widget class="QLineEdit" name="search_phrase">
            <property name="placeholderText">
             <string>Αναζήτηση βάση τίτλου ραδιοφωνικής σύνδεσης</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPushButton" name="search_button">
            <property name="text">
             <string>Αναζήτηση</string>
            </property>
            <property name="icon">
             <iconset>
              <normaloff>:/main-window/assets/images/main-window/search.png</normaloff>:/main-window/assets/images/main-window/search.png</iconset>
            </property>
           </widget>
          </item>
         </layout>
        </widget>
       </item>
       <item>
        <widget class="QFrame" name="loading_frame">
         <property name="styleSheet">
          <string notr="true">QFrame{
    border:none;
}</string>
         </property>
         <property name="frameShape">
          <enum>QFrame::StyledPanel</enum>
         </property>
         <property name="frameShadow">
          <enum>QFrame::Raised</enum>
         </property>
         <layout class="QHBoxLayout" name="horizontalLayout_2">
          <property name="leftMargin">
           <number>0</number>
          </property>
          <property name="topMargin">
           <number>0</number>
          </property>
          <property name="rightMargin">
           <number>0</number>
          </property>
          <property name="bottomMargin">
           <number>0</number>
          </property>
          <item>
           <spacer name="horizontalSpacer">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>291</width>
              <height>20</height>
             </size>
            </property>
           </spacer>
          </item>
          <item>
           <widget class="QLabel" name="loading_label">
            <property name="minimumSize">
             <size>
              <width>220</width>
              <height>20</height>
             </size>
            </property>
            <property name="maximumSize">
             <size>
              <width>220</width>
              <height>20</height>
             </size>
            </property>
            <property name="text">
             <string/>
            </property>
           </widget>
          </item>
          <item>
           <spacer name="horizontalSpacer_2">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>290</width>
              <height>20</height>
             </size>
            </property>
           </spacer>
          </item>
         </layout>
        </widget>
       </item>
       <item>
        <widget class="QLabel" name="results_label">
         <property name="styleSheet">
          <string notr="true">QLabel{
    font-weight:bold;
    text-decoration:underline;
}</string>
         </property>
         <property name="text">
          <string>Αποτέλεσμα αναζήτησης: Η αναζήτηση ολοκληρώθηκε επιτυχώς. Βρέθηκαν ... ραδιοφωνικές συνδέσεις</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignCenter</set>
         </property>
        </widget>
       </item>
       <item>
        <widget class="QTableWidget" name="table">
         <attribute name="horizontalHeaderCascadingSectionResizes">
          <bool>false</bool>
         </attribute>
         <attribute name="horizontalHeaderDefaultSectionSize">
          <number>150</number>
         </attribute>
         <attribute name="horizontalHeaderStretchLastSection">
          <bool>true</bool>
         </attribute>
         <column>
          <property name="text">
           <string>Τίτλος</string>
          </property>
         </column>
         <column>
          <property name="text">
           <string>Radio hostname</string>
          </property>
         </column>
         <column>
          <property name="text">
           <string>Ενέργεια</string>
          </property>
         </column>
        </widget>
       </item>
       <item>
        <widget class="QLabel" name="label_2">
         <property name="styleSheet">
          <string notr="true">QLabel{
    font-weight:bold;
    color:green;
}</string>
         </property>
         <property name="text">
          <string>Σημείωση 1: Η αναζήτηση πραγματοποιείτε με κριτήριο τον τίτλο των ραδιοφωνικών συνδέσεων.
Σημείωση 2: Αφήστε κένο πεδίο για εύρεση όλων των ραδιοφωνικών συνδέσεων.
Σημείωση 3: Η αναζήτηση είναι case insensitive δηλαδή θα πρέπει να δοκιμάσετε και με κεφαλαίους χαρακτήρες εφόσον δεν βρεθούν αποτελέσματα.</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignJustify|Qt::AlignVCenter</set>
         </property>
         <property name="wordWrap">
          <bool>true</bool>
         </property>
        </widget>
       </item>
       <item>
        <widget class="QPushButton" name="ok">
         <property name="text">
          <string>Εντάξει - Κλείσιμο παραθύρου</string>
         </property>
         <property name="icon">
          <iconset>
           <normaloff>:/rest-windows/assets/images/rest-windows/ok.png</normaloff>:/rest-windows/assets/images/rest-windows/ok.png</iconset>
         </property>
        </widget>
       </item>
      </layout>
     </widget>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>



source https://stackoverflow.com/questions/71161978/qdialog-with-qscrollarea-adjustsize-on-widget-hide

Comments

Popular posts from this blog

ValueError: X has 10 features, but LinearRegression is expecting 1 features as input

So, I am trying to predict the model but its throwing error like it has 10 features but it expacts only 1. So I am confused can anyone help me with it? more importantly its not working for me when my friend runs it. It works perfectly fine dose anyone know the reason about it? cv = KFold(n_splits = 10) all_loss = [] for i in range(9): # 1st for loop over polynomial orders poly_order = i X_train = make_polynomial(x, poly_order) loss_at_order = [] # initiate a set to collect loss for CV for train_index, test_index in cv.split(X_train): print('TRAIN:', train_index, 'TEST:', test_index) X_train_cv, X_test_cv = X_train[train_index], X_test[test_index] t_train_cv, t_test_cv = t[train_index], t[test_index] reg.fit(X_train_cv, t_train_cv) loss_at_order.append(np.mean((t_test_cv - reg.predict(X_test_cv))**2)) # collect loss at fold all_loss.append(np.mean(loss_at_order)) # collect loss at order plt.plot(np.log(al...

Sorting large arrays of big numeric stings

I was solving bigSorting() problem from hackerrank: Consider an array of numeric strings where each string is a positive number with anywhere from to digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array. I know it works as follows: def bigSorting(unsorted): return sorted(unsorted, key=int) But I didnt guess this approach earlier. Initially I tried below: def bigSorting(unsorted): int_unsorted = [int(i) for i in unsorted] int_sorted = sorted(int_unsorted) return [str(i) for i in int_sorted] However, for some of the test cases, it was showing time limit exceeded. Why is it so? PS: I dont know exactly what those test cases were as hacker rank does not reveal all test cases. source https://stackoverflow.com/questions/73007397/sorting-large-arrays-of-big-numeric-stings

How to load Javascript with imported modules?

I am trying to import modules from tensorflowjs, and below is my code. test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title </head> <body> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script> <script type="module" src="./test.js"></script> </body> </html> test.js import * as tf from "./node_modules/@tensorflow/tfjs"; import {loadGraphModel} from "./node_modules/@tensorflow/tfjs-converter"; const MODEL_URL = './model.json'; const model = await loadGraphModel(MODEL_URL); const cat = document.getElementById('cat'); model.execute(tf.browser.fromPixels(cat)); Besides, I run the server using python -m http.server in my command prompt(Windows 10), and this is the error prompt in the console log of my browser: Failed to loa...