Change the centralWidget's content - python-3.x

I'm begginer with qt and I have many questions.
One of them is how can I change the centralWidget's content. I have my main.py which is a
QMainWindow and contains my "menu" of my software. When I click on the "Validation" button I want change the centralWidget to show something else like the following exemple :
How would you keep just one QMainWindow and change every time I need the centralWidget ?

Related

Get the contents of a widget in a layout in PyQt

I recently decided to create a small application that simply reads the files in a compressed file and renames them. I went through several UI modules and decided to use PyQt6.
To achieve this, I first created a QWidget that holds the widgets QPushButton and QLineEdit.
The user then types the new name into the QLineEdit widget and select the QPushButton if the file has to be excluded.
Now, this widget that was created will be added into a QVBoxLayout which is then set as the QScrollArea layout.
Here's my problem:
Once I was done creating the scroll area and the list, I wanted to retrieve the content of each widget. For this purpose, I use the findChild method. But it only returns the address of the object.
Is there any way to get the text stored in QLineEdit of each widget? Is it possible to retrieve the text just by knowing its address?
Here's what I tried:
for index in range(self.layout.count()):
widget = self.layout.itemAt(index).widget()
nameFromLineEdit = widget.findChild(QLineEdit).text()
print(nameFromLineEdit)

Tkinter how to use gui in another class

I am looking to see if i could get some help and insight on the issue i am having thank you.
I have a program that runs and displays a Tkinter window with a button and a textbox (This works as intended) and the textbox is populated by (self.T.insert(tk.END,"text") and the button calls the class TwitchBot(irc.bot.SingleServerIRCBot).
The first issue i have is that when the class TwitchBot(irc.bot.SingleServerIRCBot) is called the tkinter window freezes.
i think as its a diffrent class, but am unfamillar with tkinter
The second issue is in the class TwitchBot(irc.bot.SingleServerIRCBot) i would still like to populate the textbox with (self.T.insert(tk.END,"text")
i tried to put the code here but it wasnt working well. so uploaded to github
https://github.com/isrever/bot/blob/main/bot.py

Python3 Qt5 MainWindow

I have an application flow which looks like this. At startup a MainWindow is shown and asks the user to choose a project or create a new one. After a project is created or chosen from the list, I want to close this MainWindow and open another MainWindow.
In my main.py the code looks like this:
app = QApplication([])
ui_project_list_view = ProjectListView()
ui_project_list_view.show()
app.exec_()
Now I want to close the first main window (ui_project_list_view) and open the other main window (ui_project_view). This code is called from within ui_project_list_view.
ui_project_view = ProjectView()
ui_project_view.show()
main_view.close()
No matter in which order I show or close, the application quits. How should I design my "window-flow" ?
Thanks for your help.
If you open most programs like Word or Excel- or QtDesigner for example- you'll see a blank main window initialize, and then a popup will appear asking you to choose your project.
If you wanted to apply this to your code, the ProjectView should be the main window and the ProjectListView would be the popup. The ProjectView would call this after initializing, in a setup function perhaps. After ProjectListView finishes, then ProjectView would just need to update the screen with the information that ProjectListView has.

change between menu or pause screens on libgdx

i´m trying to made a couple screens like a menu or a pause, and in these screens i want to put some "other screens", for example in my menu i want a button options and then the app slides and shows another screen with options like music/volume, or like a castlevania/megaman game when the user pause the game, some options are displayed, change the inventory, buy an hability or something like that, in this case when we try to manage the inventory the screen change an shows the information about the current inventory, so my question is how is managed this on libgdx, because i know there is a screen class but is that the way to do it?, constantly change between screens or there's another way.
This is actually what you need scene2D.
scene2d is well equipped for laying out, drawing, and handling input for game menus, HUD overlays, tools, and other UIs. The scene2d.ui package provides many actors and other utilities specifically for building UIs.
Lets assume you know about Stage which you will need to add your Actors like(buttons,textfield,input) all you have to do is implement Table, part of scene2D that contains method such as setVisible.
Lets say for example this is your log-in HUD. Now you want to hide it when a button is clicked.
Table table = new Table();
table.add(textField);
table.add(logInButton);
stage.addActor(table);
if(hideButton.isChecked())
{
table.setvisible(false)
}
else
{
table.setVisible(true)
}
This will hide all your Actors that contains in your table.

Getting pyqt application focus for popup menu to disappear when clicking away from it

Let me quickly explain the background to this. I'm developing a custom menu system inside a 3D application called Softimage XSI. It has a PyQt application object created already and ProcessEvents is being called a certain number of times every second so that PyQt applications can exist in a non-modal state within XSI.
To implement the menu, I've got a webpage embedded in a toolbar which is calling a plugin for XSI that I've written to show a PyQt menu. This all works fine (albeit, slightly contrived!).
The issue is that when I show the menu, it won't disappear when I click away from it. If I move the mouse over the menu, and then click away from it, it will disappear. It's only when it first pops up.
I've tried everything I can think of. Here's a list:
Using QtGui.qApp.installEventFilter(menu) to try and catch the mousepressed signal. It never gets triggered. I suspect the application itself isn't receiving the click.
Using menu.raise_() makes no difference
Neither does QtGui.qApp.setActiveWindow(menu)
Or menu.setFocus()
I've also tried:
event = QtGui.QMouseEvent(QtCore.QEvent.MouseMove, pos, QtCore.Qt.NoButton, QtCore.Qt.NoButton, QtCore.Qt.NoModifier)
QtGui.qApp.sendEvent(menu, event)
I had a go writing my own QEventLoop, but it just crashed XSI. I suspect trying to run a modal loop inside the other one probably isn't a legal thing to do. Either that, or I really don't know what I'm doing (equally probable)
The only thing I have partial success with is using grabMouse(). This is what makes the menu close if I click away from the menu (only after the mouse has passed over the menu once), but I have to call it a couple of times for it to "stick".
So this is my code at the moment:
class MyMenu (QtGui.QMenu):
def __init__(self, parent = None):
QtGui.QMenu.__init__(self, parent)
self.grabbed=2
def getMouse(self):
if self.grabbed>0:
self.grabMouse()
self.grabbed-=1
def paintEvent(self, event):
QtGui.QMenu.paintEvent(self, event)
self.getMouse()
def hideEvent(self, event):
self.releaseMouse()
def ShowMenu():
menu = MyMenu()
menu.addAction("A")
menu.addAction("B")
menu.addAction("C")
submenu = MyMenu()
submenu.addAction("D")
submenu.addAction("E")
submenu.addAction("F")
menu.addMenu(submenu)
menu.setTearOffEnabled(True)
menu.setStyleSheet("font: 8pt \"Sans Serif\";")
submenu.setStyleSheet("font: 8pt \"Sans Serif\";")
submenu.setTitle("Window")
submenu.setTearOffEnabled(True)
pos = QtGui.QCursor.pos()
pos.setX(105)
menu.popup(pos)
#Prevent garbage collection
QtGui.XSIMenu=menu
QtGui.XSISubMenu=submenu
#Desperate acts!
menu.raise_()
QtGui.qApp.setActiveWindow(menu)
menu.setFocus()
Any thoughts or random suggestions would be very gratefully received as this is driving me nuts! Don't be afraid to suggest modifications to stuff I've already tried, as I'm relatively new to PyQt and I may well have missed something.
Many thanks,
Andy
Just before calling popup with self.trayMenu.popup(QtGui.QCursor.pos()), call self.trayMenu.activateWindow(). Putting activateWindow before popup makes the left-click menu work the same as the right-click menu and it goes away when you click elsewhere. :)

Resources