Results 1 to 2 of 2

Thread: PyQt5 widget properties from .ui not showing in __init__ after load via uic.loadUi().

  1. #1
    Join Date
    Aug 2018
    Qt products

    Question PyQt5 widget properties from .ui not showing in __init__ after load via uic.loadUi().

    Hello all, this is a bit of a strange one. I have a subclass of QPushButton called simply Button, and I lay out a .ui file full of Buttons. I give them names and custom styles in QT Designer, but when examining these names and styles in Button's __init__() they're always blank. (This is after the call to super().__init__(…).)

    Here's the relevant fragment.
    Qt Code:
    1. class Button(QPushButton, TouchMarginPlugin):
    2. def __init__(self, parent=None, showHitRects=False):
    3. self.keepActiveLook = False
    4. super().__init__(parent, showHitRects=showHitRects)
    5. print('name', self.objectName(), self.styleSheet())
    To copy to clipboard, switch view to plain text mode 
    name and stylSheet are always ''. The name and styleSheet print correctly when I query them later, from a parent panel's __init__.

    Does anyone know why this is happening, or how to retrieve the original name when the object's being __init__'d?


  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 577 Times in 567 Posts
    Qt products
    Unix/X11 Windows Android

    Default Re: PyQt5 widget properties from .ui not showing in __init__ after load via uic.loadU

    QWidgets are not fully realized until they are "shown" (generally when their parent widget's showEvent() is executed). Visible properties (like size, position, etc.) are not valid until the layout has moved and sized child widgets prior to showing them. setupUi() merely creates the widget hierarchy, and it is the set of resize and other events prior to the showEvent() which fully fleshes it out.

    So nothing you retrieve in __init__() (or in a C++ constructor) can be trusted to be valid.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 10th May 2016, 08:06
  2. Replies: 0
    Last Post: 26th July 2015, 04:45
  3. System Error when running loadUi()
    By Amelie in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2011, 15:11
  4. Qt Designer Custom widget properties not showing in Qt Designer
    By nguarracino in forum Qt Tools
    Replies: 1
    Last Post: 19th November 2010, 14:09
  5. [4.7] QML properties load order
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 24th September 2010, 23:45

Tags for this Thread


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.