1

I am writing a houdini python script to get and sort informations. Some QGridLayout(), containing the infos, are added to a layout in the scrollAreaWidget.

My problem is that this scrollAreaWidget ( in red ) doesn't fit the main window at the start and doesn't fit the main window when it's resized.

enter image description here

def showInfo():
    # init Qt app
    app = QtWidgets.QApplication.instance()
    if not app:
        app = QApplication(sys.argv)

    pub_info = extractPubInfo()

    if len(pub_info) < 1:
        hou.ui.displayMessage("no job find")
        return

    # init main window

    win = QtWidgets.QWidget()
    win.setWindowTitle('Publish info')
    win.resize(1280, 350)
    win.setFixedHeight(350)
    p = win.palette()
    p.setColor(win.backgroundRole(), "blue")
    win.setPalette(p)

    # init main layout

    scrollArea = QtWidgets.QScrollArea(win)
    scrollArea.setWidgetResizable(True)
    scrollArea.setFixedHeight(350)

    scrollAreaWidget = QtWidgets.QWidget()
    p = scrollAreaWidget.palette()
    p.setColor(scrollAreaWidget.backgroundRole(), "red")
    scrollAreaWidget.setPalette(p)
    scrollAreaWidgetLayout = QtWidgets.QVBoxLayout(scrollAreaWidget)
    scrollArea.setWidget(scrollAreaWidget)

    for i, j in enumerate(pub_info):
        wip_color = QColor(250, 250, 250)
        out_color = QColor(250, 222, 222)
        wip_file = Path(j["wip"])
        wip_dir = wip_file.parent
        if wip_dir.exists()==False :
            wip_color = QColor(222, 55, 55)
        out_file = Path(j["out"])
        out_dir = out_file.parent
        if out_dir.exists()==False :
            out_color = QColor(222, 55, 55)
        if j["bypass"] == 1:
            wip_color = QColor(111, 111, 111)
            out_color = QColor(111, 111, 111)
        pub_task = QtWidgets.QGridLayout()

        item_name = QtWidgets.QLabel(j["node_name"])

        wipout_table = QtWidgets.QTableWidget(2,1)
        wipout_table.setFixedHeight(64)
        wipout_table.verticalHeader().setVisible(False)
        wipout_table.horizontalHeader().setVisible(False)
        wipout_table.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
        tab_item_wip = QtWidgets.QTableWidgetItem(j["wip"])
        tab_item_wip.setForeground(wip_color)
        tab_item_out = QtWidgets.QTableWidgetItem(j["out"])
        tab_item_out.setForeground(out_color)
        wipout_table.setItem(0, 0, tab_item_wip)
        wipout_table.setItem(1, 0, tab_item_out)
        pub_task.addWidget(item_name, 0, 0)
        pub_task.addWidget(wipout_table, 0, 1)

        # add 2ndary grid layout main layout
        scrollAreaWidgetLayout.addLayout(pub_task)

    win.show()
    hou.session.dummy = win
Vincent A
  • 85
  • 10

1 Answers1

1

ok i got it

    # init main window
    win = QtWidgets.QWidget()
    win.setWindowTitle('Publish info')
    win.resize(1280, 350)
    win.setFixedHeight(350)

    # init container
    conWin = QtWidgets.QWidget()

    # container layout
    conLayout = QtWidgets.QVBoxLayout(win)
    conLayout.setContentsMargins(0, 0, 0, 0)
    conWin.setLayout(conLayout)

    # scroll area
    scroll = QtWidgets.QScrollArea()
    #scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
    scroll.setWidgetResizable(True)
    #scroll.setFixedHeight(350)
    scroll.setWidget(conWin)

    # scroll layout
    scrollLayout = QtWidgets.QVBoxLayout(win)
    scrollLayout.addWidget(scroll)
    scrollLayout.setContentsMargins(0, 0, 0, 0)
Vincent A
  • 85
  • 10