Results 1 to 1 of 1

Thread: Help me maintain aspect ratio of widget within QSplitter when resizing using PyQt5

  1. #1
    Join Date
    Jul 2021
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Help me maintain aspect ratio of widget within QSplitter when resizing using PyQt5

    Hi all!

    Ubuntu Linux OS 18.04
    PyQt5

    I have a custom graph widget & a QTextEdit widget in a vertical QSplitter, and a QTabWidget in a Horizontal QSplitter.

    All resizes well, but I want the custom graph widget to keep a square aspect ratio whenever it is resized horizontally or vertically using the QSplitter.

    I want the custom graph widget to get bigger and smaller upon resizing while maintaining a square aspect ratio. I scoured google, and looked at the docs, but due to many ways of applying options nothing is outstandingly clear.

    Also, it would be nice if I could make the whole QSplitter expand when resizing the app mainwindow.

    Could someone please show me how to do both these things?

    Qt Code:
    1. from PyQt5 import QtWidgets, uic
    2. from PyQt5.QtWidgets import QTabWidget, QTabBar
    3. from pyqtgraph import PlotWidget
    4. import pyqtgraph as pg
    5. import sys
    6. import os
    7.  
    8. class MainWindow(QtWidgets.QMainWindow):
    9. def __init__(self, *args, **kwargs):
    10. super(MainWindow, self).__init__(*args, **kwargs)
    11.  
    12. # Load the UI Page
    13. self.ui = uic.loadUi("mainwindow.ui", self)
    14. """
    15. ui->UtilityTabs_tabWidget->setStyleSheet("QTabWidget::pane {"
    16. "border: 1px solid lightgray;"
    17. "background-color: rgb(245, 245, 245); }"
    18. "QTabBar::tab {"
    19. "color: lightgray;"
    20. "background-color: #654321;"
    21. "border: 1px solid red;}"
    22. "QTabBar::tab:selected {"
    23. "color: black;"
    24. "background-color: #EEEE9B;"
    25. "margin-bottom: -1px; }");
    26. """
    27. self.ui.tabWidget.setTabText(self.ui.tabWidget.indexOf(self.ui.tab), " PGN ")
    28. self.ui.tabWidget.setTabText(
    29. self.ui.tabWidget.indexOf(self.ui.tab_2), " tab 2 "
    30. )
    31. self.ui.tabWidget.setStyleSheet(
    32. "QTabWidget::pane {"
    33. "border: 1px solid lightgray;}"
    34. "QTabBar::tab {"
    35. "color: lightgray;"
    36. "background-color: #654321;"
    37. "border: 1px solid red;}"
    38. "QTabBar::tab:selected {"
    39. "color: black;"
    40. "background-color: #EEEE9B;"
    41. "padding-left: 4px;"
    42. "padding-right: 4px;"
    43. "margin-bottom: -1px; }"
    44. ) # "width: 52px;" "background-color: rgb(245, 245, 245); }" "background-color: #654321; }"
    45. # background-color: rgb(101, 67, 33); # brown
    46. # self.graphicsProxyWidget().resizeEvent()
    47. # self.ui.graphWidget.
    48.  
    49. self.plot(
    50. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]
    51. )
    52.  
    53. def plot(self, hour, temperature):
    54. self.graphWidget.plot(hour, temperature)
    55.  
    56.  
    57. def main():
    58. app = QtWidgets.QApplication(sys.argv)
    59. main = MainWindow()
    60. main.show()
    61. sys.exit(app.exec_())
    62.  
    63. if __name__ == "__main__":
    64. main()
    To copy to clipboard, switch view to plain text mode 


    SamQ
    Last edited by SamQ; 24th July 2021 at 18:46.

Similar Threads

  1. Widget with fixed aspect ratio
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2015, 21:11
  2. Replies: 3
    Last Post: 27th May 2015, 00:14
  3. QMdiSubWindow maintaining aspect ratio while resizing ?
    By Abhishek Bansal in forum Newbie
    Replies: 0
    Last Post: 9th October 2012, 17:36
  4. Replies: 1
    Last Post: 4th August 2012, 06:55
  5. keeping aspect ratio while resizing
    By franco.amato in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2009, 21:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.