Setting QWidget size

Rodrigo de Salvo Braz rodrigobraz at gmail.com
Fri Apr 23 00:09:20 BST 2021


Rich,

Yes, just like we built one container for a single tab, we could have built
multiple containers, each with its own layout and widgets, and added them
all to QTabWidget.

BTW, even the title bar and frame can be removed from a QMainWindow if you
use a window flag Qt.FramelessWindowHint, as shown below (I had to remove
qwt because it was somehow interfering with the package for that):

#!/usr/bin/env python3

import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMainWindow, QWidget, QGridLayout, QPushButton,
QTabWidget, QApplication


class TestWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        bio = QWidget(windowTitle='Test', width = 800, height = 600)

        # Layout
        container = QWidget(self)
        group1 = QGridLayout()
        container.setLayout(group1)

        savebutton = QPushButton('Save')
        savebutton.clicked.connect(self.save)
        group1.addWidget(savebutton, 0, 0)

        cancelbutton = QPushButton('Cancel')
        cancelbutton.clicked.connect(self.cancel)
        group1.addWidget(cancelbutton, 0, 1)

        tabwidget = QTabWidget(self)
        tabwidget.addTab(container, "My tab")

        self.setCentralWidget(tabwidget)

        self.setWindowFlags(Qt.FramelessWindowHint)

        self.show()

    # Methods
    def save(self):
        pass

    def cancel(self):
        pass


if __name__ == '__main__':
    app = QApplication(sys.argv)
    bio = TestWindow()
    sys.exit(app.exec())

On Thu, Apr 22, 2021 at 3:57 PM Rich Shepard <rshepard at appl-ecosys.com>
wrote:

> On Thu, 22 Apr 2021, Rodrigo de Salvo Braz wrote:
>
> > You can follow the same ideas for placing that layout with buttons in a
> > tab. You can just replace
> > self.setCentralWidget(container)
> > by
> > tabwidget = QTabWidget(self)
> > tabwidget.addTab(container, "My tab")
> > self.setCentralWidget(tabwidget)
>
> Rodrigo,
>
> If I understand correctly, I build the individual tabs in a QTabWidget
> rather than individually importing them into the main application window as
> tab/page content.
>
> > It's true that eventually you will have a QMainWindow, but that should be
> > ok, because your application will eventually need to use a window, right?
> > And of course a QMainWindow is not required to have a status bar or menu,
> > etc.
>
> Yes, the two button file is a minimum working example. There will be about
> 7
> tabs in the main application for data entry/modification.
>
> > Hope that helps.
>
> Yes, it does.
>
> I'm going to read Alan Moore's book (and finish Martin Fitzpatrick's book)
> before going back to coding. I'll still have questions but a much better
> understanding of the PyQt system.
>
> Stay well,
>
> Rich
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210422/a933ce83/attachment.htm>


More information about the PyQt mailing list