Home > Enterprise >  how can i add a new widget such as GroupBox or Frame floating on the window in PyQt5?
how can i add a new widget such as GroupBox or Frame floating on the window in PyQt5?

Time:12-15

i am working on a program and it has a window contain a layout,

i have button on the window when the user presse it there is a QFrame will appear on the window in the middle of the window without add it in the layout , like the picture below :

enter image description here

is there a way to show widget on the window and control its position ?

CodePudding user response:

in the first thank for everyone.

i knew the solution now.

the solution is when you add a new widget on the window you need to show it using show method.

this is an example:

gourp_box = QtWidgets.QFrame(self.window)
gourp_box.setFixedSize(300,160)
gourp_box.show()

but i faced complexity to make that widget follows the user's box and i decided to change this way to show the choices

and like what mugiseyebrows user said in the comments you can use QMenu but QMenu is not good for my purpose then i used QMenuBar:

menu_bar = QtWidgets.QMenuBar(self.window)
button = menu_bar .addMenu("...")
button .addAction("Edit user's data")
button .addAction("Delete the user")

the results :

enter image description here

yes i know it is not a professional result but i will style it using css

  • Related