Results 1 to 2 of 2

Thread: Function who return a layout

  1. #1
    Join Date
    Apr 2019
    Posts
    13
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Function who return a layout

    HI,
    my gui has one horizontalbox layout, who has a left panel and a right panel.

    I have wrote a function to populate the left panel with the widgets that I need. They are inside a verticalbox:

    def rightPanel(self):
    verticalboxRP=QVBoxLayout()
    welcomeText = QLabel("Android Forensic Automator (AnForA)\n a software tool that automates the forensic analysis of Android applications", self)
    verticalboxRP.addWidget(welcomeText)
    self.setLayout(verticalboxRP)
    self.show()

    I have a similar function for the left panel.

    Now the problem is: since I like to keep the creation of the left and right panel in separate functions, how can I use these functions in order to add them in the main gui who has a horizontal box layout.

    My attempt to create the main window was something like this:

    def UI(self):
    horizontalbox=QHBoxLayout()
    rightPanel(horizontalbox)
    leftPanel(horizontalbox)

    #horizontalbox.addLayout(lp)
    #horizontalbox.addLayout(rp)

    self.setLayout(horizontalbox)
    self.show()

    but, of course, I get error since I'm not very confident with pyqt and with python too (sorry).

    Could you help me to figure out how can I manage a horizontal box who contains two vertical box layouts?
    Below my signature, my current code.

    Thanks.

    Massimo
    Qt Code:
    1. import sys
    2. from PyQt5.QtWidgets import *
    3. from PyQt5.QtGui import QPixmap
    4.  
    5. class Window(QWidget):
    6. def __init__(self):
    7. super().__init__()
    8. self.setWindowTitle("some text")
    9. #self.setGeometry(50,50,500,500) #if I want set the size
    10. self.UI()
    11.  
    12. def UI(self):
    13. horizontalbox=QHBoxLayout()
    14. rightPanel(horizontalbox)
    15. leftPanel(horizontalbox)
    16.  
    17. #horizontalbox.addLayout(lp)
    18. #horizontalbox.addLayout(rp)
    19.  
    20. self.setLayout(horizontalbox)
    21. self.show()
    22.  
    23.  
    24. def rightPanel(horizontalbox):
    25. verticalboxRP=QVBoxLayout()
    26. welcomeText = QLabel("some text", self)
    27. verticalboxRP.addWidget(welcomeText)
    28. self.setLayout(verticalboxRP)
    29.  
    30. #self.show()
    31.  
    32. def leftPanel(self):
    33. verticalboxLP=QVBoxLayout()
    34.  
    35. image = QLabel(self)
    36. image.setPixmap(QPixmap('logoUPO.png'))
    37. text = QLabel("AnForA\n Android Forensic Automator", self)
    38. installAPKBtn = QPushButton("Install APK on the device", self)
    39. detectPathBtn = QPushButton("Detect analysis paths", self)
    40. startExpBtn = QPushButton("Start experiment", self)
    41. analyzeResBtn = QPushButton("Analyze results", self)
    42. quitBtn = QPushButton("quit", self)
    43.  
    44. verticalbox.addWidget(image)
    45. verticalbox.addWidget(text)
    46. verticalbox.addWidget(installAPKBtn)
    47. verticalbox.addWidget(detectPathBtn)
    48. verticalbox.addWidget(startExpBtn)
    49. verticalbox.addWidget(analyzeResBtn)
    50. verticalbox.addWidget(quitBtn)
    51.  
    52. self.setLayout(verticalboxLP)
    53.  
    54. self.show()
    55.  
    56. def installAPK(self):
    57. pass
    58.  
    59. def detectPath(self):
    60. pass
    61.  
    62. def main():
    63. App = QApplication(sys.argv)
    64. window = Window()
    65. sys.exit(App.exec_())
    66.  
    67. if __name__=='__main__':
    68. main()
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2019
    Posts
    13
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Function who return a layout

    I think I have solved it by using what you see at the end of this post (maybe someone will have the same problem).
    Sorry
    M
    Qt Code:
    1. def UI(self):
    2. mainScreen=QHBoxLayout()
    3.  
    4. leftPanel = QVBoxLayout()
    5. rightPanel = QVBoxLayout()
    6.  
    7. self.loadLeftPanel(leftPanel)
    8. self.loadRightPanel(rightPanel)
    9.  
    10. #horizontalbox.addLayout(lp)
    11. #horizontalbox.addLayout(rp)
    12.  
    13. mainScreen.addLayout(leftPanel)
    14. mainScreen.addWidget(line)
    15. mainScreen.addLayout(rightPanel)
    16.  
    17. self.setLayout(mainScreen)
    18. self.show()
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to return QtListWidget from function
    By bandito in forum Qt Programming
    Replies: 2
    Last Post: 11th July 2016, 17:35
  2. function to return QSQLquerymodel
    By cpuinthebrain in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2015, 13:12
  3. Replies: 1
    Last Post: 2nd January 2013, 10:48
  4. How to return QString from function
    By Rondle in forum Newbie
    Replies: 3
    Last Post: 21st November 2012, 19:51
  5. Function return
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2009, 01:52

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.