Skip to content

main_window

_main_window

Custom main window widget.

Classes:

Name Description
FXMainWindow

Customized QMainWindow class.

Classes

FXMainWindow

FXMainWindow(
    parent: Optional[QWidget] = None,
    icon: Optional[Union[str, QIcon]] = None,
    title: Optional[str] = None,
    size: Optional[Tuple[int, int]] = None,
    documentation: Optional[str] = None,
    project: Optional[str] = None,
    version: Optional[str] = None,
    company: Optional[str] = None,
    ui_file: Optional[str] = None,
    set_stylesheet: bool = True,
    rich_tooltips: Optional[bool] = None,
    toolbar: bool = True,
    fit_to_contents: bool = False,
)

Bases: FXThemeAware, QMainWindow


              flowchart TD
              fxgui.fxwidgets._main_window.FXMainWindow[FXMainWindow]
              fxgui.fxstyle.FXThemeAware[FXThemeAware]

                              fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._main_window.FXMainWindow
                


              click fxgui.fxwidgets._main_window.FXMainWindow href "" "fxgui.fxwidgets._main_window.FXMainWindow"
              click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
            

Customized QMainWindow class.

Parameters:

Name Type Description Default
parent
QWidget

Parent widget. Defaults to hou.qt.mainWindow().

None
icon
str or QIcon

The window's icon: a path to an image, or a QIcon for an application whose mark comes out of an icon set rather than off disk. With neither, an icon already set on the running QApplication is left in place and fxgui's own logo is used only if there is none. Defaults to None.

None
title
str

Title of the window. Defaults to None.

None
size
Tuple[int, int]

Window size as width and height. Defaults to None.

None
documentation
str

URL to the tool's documentation. Defaults to None.

None
version
str

Version label for the window. Defaults to None.

None
company
str

Company name for the window. Defaults to Company.

None
ui_file
str

Path to the UI file for loading. Defaults to None.

None
set_stylesheet
bool

Whether to set the default stylesheet. Defaults to True.

True
rich_tooltips
bool

Whether to install the global FXTooltipManager, which replaces Qt tooltips application-wide with FXTooltip. None (default) and False both leave it uninstalled, so tooltips are Qt's own, styled by the QToolTip rule and formatted by fxwidgets.apply_tip. Pass True to opt in to the manager's behaviour: tooltips that stay up while hovered, an arrow anchored to the widget, configurable delays, icons and images inside a tooltip, and automatic tooltips built from FXThumbnailDelegate roles in item views. Defaults to None.

None
toolbar
bool

Whether to build the window's toolbar. False skips it entirely and leaves self.toolbar as None, for an application with no trigger for any of its four buttons. Not built rather than built and hidden: a hidden toolbar comes back through the menu bar's own right-click "Toolbars" entry. Defaults to True.

True
fit_to_contents
bool

Whether to grow to the layout's own sizeHint on first show, grow-only and bounded by the screen. The size set in the constructor is chosen before a subclass has put anything inside the window, so a window with more in it than that opens clamped. Off by default, since changing the opening size of every existing window is not something to do silently. Defaults to False.

False

Methods:

Name Description
center_on_screen

Center the window on the primary screen.

closeEvent

Handle the window close event.

get_available_themes

Get a list of all available theme names.

hide_banner

Hides the banner.

hide_status_line

Hides the status line.

setCentralWidget

Override the QMainWindow's setCentralWidget method.

setWindowTitle

Override the setWindowTitle method.

set_banner_icon

Sets the icon of the banner.

set_banner_text

Sets the text of the banner.

set_company_label

Sets the company label in the status bar.

set_project_label

Sets the project label in the status bar.

set_status_line_colors

Set the colors of the status line.

set_theme

Set the theme of the window.

set_ui_file

Sets the UI file and loads the UI.

set_version_label

Sets the version label in the status bar.

showEvent

Grow to the layout's own size, if this window asked to.

show_banner

Shows the banner.

show_status_line

Shows the status line.

statusBar

Returns the FXStatusBar instance associated with this window.

toggle_theme

Toggle the theme of the window to the next available theme.

Methods:
center_on_screen
center_on_screen() -> None

Center the window on the primary screen.

This method centers the window on the available screen geometry, accounting for taskbars and other system UI elements.

Examples:

>>> window = FXMainWindow()
>>> window.resize(800, 600)
>>> window.center_on_screen()
>>> window.show()
closeEvent
closeEvent(event: QCloseEvent) -> None

Handle the window close event.

Parameters:

Name Type Description Default
event QCloseEvent

The close event.

required
get_available_themes
get_available_themes() -> List[str]

Get a list of all available theme names.

Returns:

Type Description
List[str]

List[str]: List of theme names (e.g., ["dark", "light"]).

Examples:

>>> window = FXMainWindow()
>>> themes = window.get_available_themes()
>>> print(themes)  # ['dark', 'light']
hide_banner
hide_banner() -> None

Hides the banner.

hide_status_line
hide_status_line() -> None

Hides the status line.

setCentralWidget
setCentralWidget(widget: QWidget) -> None

Override the QMainWindow's setCentralWidget method.

Ensures that the status line is always at the bottom of the window and the banner is always at the top.

Parameters:

Name Type Description Default
widget QWidget

The widget to set as the central widget.

required
Note

Overrides the base class method.

setWindowTitle
setWindowTitle(title: str) -> None

Override the setWindowTitle method.

Parameters:

Name Type Description Default
title str

The new window title.

required
set_banner_icon
set_banner_icon(icon: Optional[Union[QIcon, str]], size: int = 20) -> None

Sets the icon of the banner.

Parameters:

Name Type Description Default
icon Optional[Union[QIcon, str]]

The icon to set in the banner. Can be a QIcon or an icon name string for theme-aware icons.

required
size int

The size of the icon. Defaults to 20.

20
Note

Using an icon name string (e.g., "widgets") is recommended for theme-aware icons that automatically update when the theme changes.

set_banner_text
set_banner_text(text: str) -> None

Sets the text of the banner.

Parameters:

Name Type Description Default
text str

The text to set in the banner.

required
set_company_label
set_company_label(company: str) -> None

Sets the company label in the status bar.

Parameters:

Name Type Description Default
company str

The company name.

required
set_project_label
set_project_label(project: str) -> None

Sets the project label in the status bar.

Parameters:

Name Type Description Default
project str

The project name.

required
set_status_line_colors
set_status_line_colors(color_a: str, color_b: str) -> None

Set the colors of the status line.

Parameters:

Name Type Description Default
color_a str

The first color of the gradient.

required
color_b str

The second color of the gradient.

required
set_theme
set_theme(theme: str) -> str

Set the theme of the window.

This method can be called from external code to apply a specific theme, including when running inside a DCC like Houdini, Maya, or Nuke where you don't have direct access to QApplication.

Parameters:

Name Type Description Default
theme str

The theme name to apply (e.g., "dark", "light", or custom).

required

Returns:

Name Type Description
str str

The theme that was applied.

Examples:

>>> window = FXMainWindow()
>>> window.show()
>>> window.set_theme("light")
>>> window.set_theme("dark")
set_ui_file
set_ui_file(ui_file: str) -> None

Sets the UI file and loads the UI.

Parameters:

Name Type Description Default
ui_file str

Path to the UI file to load.

required
set_version_label
set_version_label(version: str) -> None

Sets the version label in the status bar.

Parameters:

Name Type Description Default
version str

The version string.

required
showEvent
showEvent(event) -> None

Grow to the layout's own size, if this window asked to.

The size set in the constructor is a constant chosen before the subclass had put anything inside the window, so it knows nothing about its own contents. Measured on a window with a log panel in it: opened 500x674 against a sizeHint of 506x931, which pinned every widget to its minimum and left the panel four lines tall. A window that opens smaller than it asks for is showing a clamped version of itself.

Opt-in through fit_to_contents, and off by default on purpose: changing the opening size of every window built on this class is not something to do silently.

Grow-only, so a caller that asked for a larger window keeps it, and once only, so a window an artist has dragged smaller is not pushed back out on its next show. Bounded by the screen, since a layout may ask for more room than the display has and a window taller than the desktop is worse than a scrollbar.

The screen is asked for the way the rest of this module asks, behind the Qt major-version guard: QWidget.screen() arrived in Qt 5.14, so on a host running PySide2 against anything older -- Maya 2020 and its generation -- it raises AttributeError from inside a showEvent, which is a hard failure at window-show time. Both arms name the screen the WINDOW is on rather than the primary one, or a first show on a two-monitor desktop is bounded by the wrong display.

show_banner
show_banner() -> None

Shows the banner.

show_status_line
show_status_line() -> None

Shows the status line.

statusBar
statusBar() -> FXStatusBar

Returns the FXStatusBar instance associated with this window.

Returns:

Name Type Description
FXStatusBar FXStatusBar

The FXStatusBar instance associated with this window.

Note

Overrides the base class method.

toggle_theme
toggle_theme() -> str

Toggle the theme of the window to the next available theme.

This method can be called from external code to cycle through themes, including when running inside a DCC like Houdini, Maya, or Nuke where you don't have direct access to QApplication.

Returns:

Name Type Description
str str

The new theme that was applied.

Examples:

>>> window = FXMainWindow()
>>> window.show()
>>> new_theme = window.toggle_theme()
>>> print(f"Switched to {new_theme} theme")