PyQt: Setting pushbutton color on Big Sur - pyqt

On Ubuntu 18.04, the following code produces a simple pushbutton with a green background and red text; On Big Sur the background remains unchanged - any thoughts?
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtGui as qtg
app = qtw.QApplication([])
button = qtw.QPushButton('Pushbutton')
palette = button.palette()
palette.setColor(qtg.QPalette.Button, qtg.QColor('green'))
palette.setColor(qtg.QPalette.ButtonText, qtg.QColor('red'))
button.setPalette(palette)
button.show()
app.exec()

Related

why does PyQt5 show a black box instead of a canvas [duplicate]

This question already has answers here:
Strange pixels drawn on QPixmap
(1 answer)
Qt: Empty transparent QImage has noise
(1 answer)
Closed 4 months ago.
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtCore import Qt
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.label = QtWidgets.QLabel()
canvas = QtGui.QPixmap(400, 300)
self.label.setPixmap(canvas)
self.setCentralWidget(self.label)
self.draw_something()
def draw_something(self):
painter = QtGui.QPainter(self.label.pixmap())
painter.drawLine(10, 10, 300, 200)
painter.end()
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
Im trying to learn about graphics in Qt5 following the tutorials I came across this code why does it produce a black canvas ,im using ubuntu with a window manager i3

QSplashScreen not showing image pyqt5

I am trying to show splashscreen before loading the mainwindow but a transparent window is displayed instead of the intended image. The splashscreen is supposed to be displayed after import and instantiation loading of Dashboard, which takes a few seconds, but the image only shows when the splash screen is about to close. Below is my code:
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QThread
from PyQt5.QtGui import QPixmap
from modules.video_opening.map.map import Map
import sys
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
splash_pic = QPixmap('splash.png')
splash = QtWidgets.QSplashScreen(splash_pic, Qt.WindowStaysOnTopHint)
splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
splash.setEnabled(False)
splash.setMask(splash_pic.mask())
splash.showMessage("<h6>Loading...</h6>", Qt.AlignBottom | Qt.AlignRight, Qt.black)
splash.show()
app.processEvents()
from modules.dashboard import Dashboard
dashboard = Dashboard()
splash.finish(dashboard)
dashboard.show()
app.exec_()
Here's what's working for me at the moment: adding a loop of app.processEvents()
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QThread
from PyQt5.QtGui import QPixmap
from modules.video_opening.map.map import Map
import sys
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
splash_pic = QPixmap('splash.png')
splash = QtWidgets.QSplashScreen(splash_pic, Qt.WindowStaysOnTopHint)
splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
splash.setEnabled(False)
splash.setMask(splash_pic.mask())
splash.showMessage("<h6>Loading...</h6>", Qt.AlignBottom | Qt.AlignRight, Qt.black)
splash.show()
for i in range(10000):
app.processEvents()
from modules.dashboard import Dashboard
dashboard = Dashboard()
splash.finish(dashboard)
dashboard.show()
app.exec_()

how to set a theme for ttkthemes for python3 in windows10?

I'm trying to style my tkinter GUI with some theme from ttkthemes.
I have found this code :
from ttkthemes import ThemedStyle
import tkinter as tk
from tkinter import ttk
app = tk.Tk()
app.title('App')
style = ThemedStyle(app)
style.set_theme("black")
tktext = tk.Label(app, text=" tk Label")
tktext.pack()
tkbutton = tk.Button(app, text="tk Button")
tkbutton.pack()
text = ttk.Label(app, text=" ttk Label")
text.pack()
button = ttk.Button(app, text="ttk Button")
button.pack()
app.geometry('200x200')
app.mainloop()
in this topic :
Python - How do I add a theme from ttkthemes package to a guizero application?
but I have a problem with that and that's when I run the program the theme doesn't cover whole root windows and just the buttons or labels from ttk are taking the theme (using windows10).I have tried in some other codes and everytime the same problem.
What's Problem with that?
ttktheme
Themes only apply to widgets from the ttk module. For widgets not in ttk, such as the text widget, you have to configure them individually.

Not getting the WINDOW on using PYQT4 in ubuntu16

Here is my simple code to make a window using pyqt4 , but after running the code gets compiled but not showing any window.
import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
app = QApplication(sys.argv)
window = QWidget()
window.show()
If there is some error in the code please correct me .

.show() not working in PtQt4

When I run the code below, I should be able to see a new window that I created. However, when I run it, I can see the new window appearing for a split second and disappearing. What could be the problem?
import sys
from PyQt4 import QtGui
applicationDefinition = QtGui.QApplication(sys.argv)
windowFigure = QtGui.QWidget()
windowFigure.show()
import sys
from PyQt4 import QtGui
applicationDefinition = QtGui.QApplication(sys.argv)
windowFigure = QtGui.QWidget()
windowFigure.show()
applicationDefinition.exec_()

Resources