Custom widget does not appear on Main Window

Şener

I've trying to create a custom widget and make it appear on Grid Layout on the main window.

class MyCustomWidget(QtGui.QWidget):
    def __init__(self):
        super(MyCustomWidget, self).__init__()
        self.setupUi()

    def setupUi(self):
        self.testText = QtGui.QLabel()
        font = QtGui.QFont()
        font.setPointSize(8)
        font.setBold(True)
        font.setWeight(75)
        self.testText.setFont(font)
        self.testText.setAlignment(QtCore.Qt.AlignCenter)
        self.testText.setObjectName(_fromUtf8("patientText"))
        self.testText.setText("Test")

class UIMainWindow(object):
    def setupUi(self, MainWindow):
        ...
        self.gridLayout = QtGui.QGridLayout()
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        ...

        self.test = MyCustomWidget()
        self.gridLayout.addWidget(self.test)

When I run this code, main window appears but there is nothing about the widget that I created. If I simply add an QLabel to grid layout, it appears.

Valentin B.

As is, your MyCustomWidget is simply a standard widget with an attribute testText containing a QLabel. If you want it to contain subwidgets that will show on your main window, you need to instantiate a layout, add the sub widgets to the layout, then add the layout to MyCustomWidget:

At the end of MyCustomWidget's setupUi

self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setObjectName(_fromUtf8("MyCustomWidgetLayout"))

self.gridLayout.addWidget(self.testText)

#add all other widgets here

self.setLayout(self.gridLayout)

You can also create embedded layouts, by calling addLayout method on the parent layout and passing it the child layout !

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Q_PROPERTY of type float on custom widget does not appear in the Property Editor

From Dev

Custom directive does not appear in the page

From Dev

yii2 star widget does not appear

From Dev

ggvis visualization does not appear in main pane

From Dev

WPF main window does not return

From Dev

ROS Image subscriber - window popup does not appear

From Dev

Google Geocoding - custom marker does not appear

From Dev

Custom events does not appear even if the are sent

From Dev

Application does not appear in taskbar when launched & stays behind main Application

From Dev

Why does a Toplevel window get destroyed when the main window is minimized?

From Dev

How do I purge Pantheon desktop?/Why does this window appear?

From Dev

Why does `vagrant up` cause the VirtualBox VM window to appear?

From Dev

Firefox seems fully loaded, but browser window does not appear for minutes

From Dev

Middle-click does nothing but makes window controls appear

From Dev

xmobar does not appear on top of window stack when xmonad starts

From Dev

How do I purge Pantheon desktop?/Why does this window appear?

From Dev

Why does the menu bar appear only when the window is maximized?

From Dev

QT scrollbar does not appear when the size of the content exceeds the window size

From Dev

How to set a property of a custom control from the main window?

From Dev

WPF Window set custom startup location/position within main screen

From Dev

pyqt5 custom dialog input popup within main window

From Dev

Custom Post Type does not appear in nav_menu

From Dev

add_custom_target does not appear to properly expand variable in cmake

From Dev

Custom plugin module does not appear while creating new project in WebStorm

From Dev

Custom property does not show in properties window

From Dev

How To Let Your Main Window Appear after succesful login in Tkinter(PYTHON 3.6

From Dev

Main window does not receive events after modal dialog is closed

From Dev

Modal dialog box does not communicate with main HTA window

From Dev

How to call and pack widget class frames into a main window application class? tkinter

Related Related

  1. 1

    Q_PROPERTY of type float on custom widget does not appear in the Property Editor

  2. 2

    Custom directive does not appear in the page

  3. 3

    yii2 star widget does not appear

  4. 4

    ggvis visualization does not appear in main pane

  5. 5

    WPF main window does not return

  6. 6

    ROS Image subscriber - window popup does not appear

  7. 7

    Google Geocoding - custom marker does not appear

  8. 8

    Custom events does not appear even if the are sent

  9. 9

    Application does not appear in taskbar when launched & stays behind main Application

  10. 10

    Why does a Toplevel window get destroyed when the main window is minimized?

  11. 11

    How do I purge Pantheon desktop?/Why does this window appear?

  12. 12

    Why does `vagrant up` cause the VirtualBox VM window to appear?

  13. 13

    Firefox seems fully loaded, but browser window does not appear for minutes

  14. 14

    Middle-click does nothing but makes window controls appear

  15. 15

    xmobar does not appear on top of window stack when xmonad starts

  16. 16

    How do I purge Pantheon desktop?/Why does this window appear?

  17. 17

    Why does the menu bar appear only when the window is maximized?

  18. 18

    QT scrollbar does not appear when the size of the content exceeds the window size

  19. 19

    How to set a property of a custom control from the main window?

  20. 20

    WPF Window set custom startup location/position within main screen

  21. 21

    pyqt5 custom dialog input popup within main window

  22. 22

    Custom Post Type does not appear in nav_menu

  23. 23

    add_custom_target does not appear to properly expand variable in cmake

  24. 24

    Custom plugin module does not appear while creating new project in WebStorm

  25. 25

    Custom property does not show in properties window

  26. 26

    How To Let Your Main Window Appear after succesful login in Tkinter(PYTHON 3.6

  27. 27

    Main window does not receive events after modal dialog is closed

  28. 28

    Modal dialog box does not communicate with main HTA window

  29. 29

    How to call and pack widget class frames into a main window application class? tkinter

HotTag

Archive