how to get parent control dimension. #716
Replies: 4 comments 2 replies
-
Would you share a code sample please? |
Beta Was this translation helpful? Give feedback.
-
import flet
import flet as ft
class LeftPanel(ft.UserControl):
def __init__(self):
super().__init__()
def build(self):
return ft.Column(
controls=[
ft.Container(
bgcolor=ft.colors.BLUE,
width=300,
height=300
),
ft.Container(
bgcolor=ft.colors.RED_50,
width=300,
height=300
),
]
)
class RightPanel(ft.UserControl):
def __init__(self):
super().__init__()
def build(self):
return ft.Column(
controls=[
ft.Container(
bgcolor=ft.colors.BLUE,
width=600,
height=300
),
ft.Container(
bgcolor=ft.colors.RED_50,
width=600,
height=300
),
]
)
def main(page):
page.add(
ft.Row(
controls=[
LeftPanel(),
RightPanel()
]
)
)
flet.app(target=main) I don't want to hardcode the height and width in the above code. It should be derived from the current screen dimensions so I can use the entire screen properly. If you execute the above you can observe there is space available on the right side of the screen. |
Beta Was this translation helpful? Give feedback.
-
Please what did you mean by 'parent'? def __init__(self):
super().__init__()
self.expand = True |
Beta Was this translation helpful? Give feedback.
-
Maybe you could change your init of your control and pass the width and height of your page. I don't see how UserControl could have access to this, self.page is a NoneType. When you call your UserControl, you pass by arguments.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to create a container with the maximum available space, whenever I use expand=True output goes blank. If I get the parent widget size then I can set the width and height for the container. Is there any way to know the parent size similar to MediaQuery in flutter?
Beta Was this translation helpful? Give feedback.
All reactions