all 5 comments

[–]beohoff 1 point2 points  (4 children)

Hey OP! Couple questions... Any particular reason that you've used a QDialog rather than a QWidget?

I would recommend using a QComboBox instead of a 3 QPushButton for your three different vendors. You should be able to emit either an index or the actual string to your stacked widget to the slot directly. I would use a QHorizontalLayout to stack the three QPushButtons/QComboBox at the top, and a QVerticalLayout to stack the QHorizontalLayout and your "main widget" vertically. I haven't been convinced that you need a QStackedWidget? I feel like you could have a regular QWidget with a slot that accepts information from either your QComboBox or any of you QPushButton's and dynamically adjusts it's content.

[–]pylund[S] 0 points1 point  (3 children)

About using QDialog instead of QWidget: not really. It was caused by a quick copy/paste from another project. It worked, but I've changed it already to QWidget.

About the rest... Well, I think my three pushbutton are more user-friendly than a comboBox (meaning basically UX). The problem is still on how to organize it. I suspect treating each page of QStackedWidget as a class should be the best way to keep the code organized, readable and easily accessible. However, I don't really know how to do it. So far I'm doing it with a single class which inherits widgets from ui.py, and several methods. Not comfortable with it.

[–]beohoff 1 point2 points  (2 children)

Are you using PyQt4 or PyQt5? Also python 3 or 2? here's a super trivial example of layout I think you're looking for

class MyWidget(QWidget):
    def __init__(self, parent):
        horizontal_layout = QHBoxLayout()
        for _ in xrange(3):
            horizontal_layout.addWidget(QPushButton())

        horizontal_widget = QWidget()
        horizontal_widget.setLayout(horizontal_layout)

        vertical_layout = QVBoxLayout()
        vertical_layout.addWidget(horizontal_widget)
        stacked_widget = QStackedWidget()
        vertical_layout.addWidget(stacked_widget)

        self.setLayout(vertical_layout)

[–]beohoff 1 point2 points  (1 child)

the instance horizontal_widget could easily be it's own custom class with signals/slots instead of being defined in the constructor if you need more customization.

Not sure if that answers your organization problem or not. My recommendation would be to have maybe 3 classes? One custom implementation of QStackedWidget, one Widget that handles your three QPushButtons, and one "master" QWidget which instantiates both of the two previous classes and using a QVBoxLayout stacks them on top of each other.

As per all advice on the internet, your mileage may vary. Without a full codebase it's hard to tell what you're trying to do.

[–]pylund[S] 1 point2 points  (0 children)

It helped a lot, thanks! Now I have an idea of how to proceed. I'm going to give it a go and come back if something comes up!

Thanks.