Here is a simple example of a chat application with bubble messages using PySide6:
import PySide6
from PySide6 import QtCore, QtGui, QtWidgets
class ChatMessage(QtWidgets.QWidget):
def __init__(self, text, author):
super().__init__()
self.layout = QtWidgets.QVBoxLayout(self)
self.author_label = QtWidgets.QLabel(author)
self.layout.addWidget(self.author_label)
self.text_label = QtWidgets.QLabel(text)
self.text_label.setWordWrap(True)
self.layout.addWidget(self.text_label)
# Add styling
self.setStyleSheet("""
border: 1px solid gray;
border-radius: 8px;
padding: 8px;
margin-bottom: 8px;
""")
class ChatWindow(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.messages_layout = QtWidgets.QVBoxLayout()
self.messages_widget = QtWidgets.QWidget()
self.messages_widget.setLayout(self.messages_layout)
# Add message input controls
self.input_layout = QtWidgets.QHBoxLayout()
self.message_input = QtWidgets.QLineEdit()
self.send_button = QtWidgets.QPushButton("Send")
self.send_button.clicked.connect(self.send_message)
self.input_layout.addWidget(self.message_input)
self.input_layout.addWidget(self.send_button)
self.main_layout = QtWidgets.QVBoxLayout(self)
self.main_layout.addWidget(self.messages_widget)
self.main_layout.addLayout(self.input_layout)
def send_message(self):
msg = self.message_input.text()
if msg:
# Add message to layout
message = ChatMessage(msg, "You")
self.messages_layout.addWidget(message)
# Clear input
self.message_input.clear()
app = QtWidgets.QApplication([])
window = ChatWindow()
window.show()
app.exec()
This creates a basic chat UI with bubble messages. To support audio, you can add a file picker and send audio files instead of/in addition to text. Let me know if any part needs more explanation!