Results 1 to 3 of 3

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

  1. #1
    Join Date
    Aug 2018
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    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?

    Thanks!
    –DDR

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,812
    Thanks
    216
    Thanked 590 Times in 580 Posts
    Qt products
    Qt5
    Platforms
    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.

  3. #3
    Join Date
    Aug 2018
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

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

    Ahhh, thank you! This helps quite a bit.

Similar Threads

  1. Replies: 2
    Last Post: 10th May 2016, 09:06
  2. Replies: 0
    Last Post: 26th July 2015, 05:45
  3. System Error when running loadUi()
    By Amelie in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2011, 16: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, 15:09
  5. [4.7] QML properties load order
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 25th September 2010, 00:45

Tags for this Thread

Bookmarks

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.