Qt diseñador vista diferente de GUI real en Python
Cuando trato de ejecutar este código de ui convertido a .py, mi primera página para mi widget apilado parece haber perdido su hoja de estilo que lo he dado en el desginer, pero las otras páginas en los widgets apilados están bien cuando yo también las probé. Pls ayuda
Vista previa: Estilo de fusión:
Vista previa: Windows Vista Estilo:
Vista previa: Window Xp Style:
Avance: Estilo de Windows:
Guión real:
Aquí está el archivo ui
xml version="1.0" encoding="UTF-8"?
Form
0
0
1080
720
0
0
800
600
1920
1080
Form
false
*{
background-color:qlineargradient(spread:reflect, x1:0.5, y1:0.539409, x2:0.5, y2:1, stop:0 rgba(116, 119, 131, 255), stop:1 rgba(145, 148, 163, 255));
}
-
1
1
540
610
QFrame::StyledPanel
QFrame::Raised
0
540
610
titleWindowContainer
QWidget{
border-radius: 15px;
background:none;
}
QWidget[accessibleName = titleWindowContainer]{
border: 5px solid rgb(38, 38, 38);
background: rgb(107, 113, 140);
}
-1
-1
541
401
1
1
QLabel{
background: none;
font: 60px "Imprint MT Shadow";
qproperty-alignment: AlignCenter;
}
LIBRARY MANAGEMENT SYSTEM
true
30
430
171
101
1
1
QPushButton:hover{
background: qlineargradient(spread:reflect, x1:0.5, y1:0.539409, x2:0.5, y2:1, stop:0 rgba(116, 119, 131, 255), stop:1 rgba(145, 148, 163, 255));
font-family: "Arial", sans-serif;
font-size: 30px;
border-radius: 20px;
font-weight: bold;
}
QPushButton{
background:qlineargradient(spread:pad, x1:0.503, y1:1, x2:0.503, y2:0, stop:0 rgba(82, 87, 120, 255), stop:1 rgba(125, 130, 127, 255));
font-family: "Arial", sans-serif;
font-size: 30px;
border-radius: 20px;
font-weight: bold;
}
QPushButton:pressed{
background: qlineargradient(spread:reflect, x1:0, y1:0.9995, x2:0.477, y2:0.522955, stop:0.154229 rgba(104, 111, 153, 255), stop:1 rgba(152, 163, 223, 255));
font-family: "Arial", sans-serif;
font-size: 30px;
border-radius: 20px;
font-weight: bold;
border: 2px solid black;
}
ADMIN
340
430
171
101
1
1
QPushButton:hover{
background: qlineargradient(spread:reflect, x1:0.5, y1:0.539409, x2:0.5, y2:1, stop:0 rgba(116, 119, 131, 255), stop:1 rgba(145, 148, 163, 255));
font-family: "Arial", sans-serif;
font-size: 30px;
border-radius: 20px;
font-weight: bold;
}
QPushButton{
background:qlineargradient(spread:pad, x1:0.503, y1:1, x2:0.503, y2:0, stop:0 rgba(82, 87, 120, 255), stop:1 rgba(125, 130, 127, 255));
font-family: "Arial", sans-serif;
font-size: 30px;
border-radius: 20px;
font-weight: bold;
}
QPushButton:pressed{
background: qlineargradient(spread:reflect, x1:0, y1:0.9995, x2:0.477, y2:0.522955, stop:0.154229 rgba(104, 111, 153, 255), stop:1 rgba(152, 163, 223, 255));
font-family: "Arial", sans-serif;
font-size: 30px;
border-radius: 20px;
font-weight: bold;
border: 2px solid black;
}
MEMBER
200
430
141
101
1
1
QLabel{
background: none;
font-family: "Arial";
}
LOGIN AS
false
Qt::AlignCenter
true
memberLoginContainer
QWidget{
border-radius: 15px;
background:none;
}
QWidget[accessibleName = memberLoginContainer]{
border: 5px solid rgb(38, 38, 38);
background: rgb(107, 113, 140);
}
0
240
540
370
Qt::LeftToRight
QFrame::StyledPanel
QFrame::Raised
150
160
240
40
0
0
240
40
240
40
Arial
13
QLineEdit{
background:rgb(114, 120, 149);
border: 2px solid rgb(152, 161, 199);
padding-left: 10px;
}
QLineEdit:hover{
background:rgb(114, 120, 149);
border: 2px solid rgb(181, 192, 236);
padding-left: 10px;
}
QLineEdit:focus{
background:rgb(114, 120, 149);
border: 2px solid rgb(255, 160, 6);
padding-left: 10px;
}
username
150
230
240
40
0
0
240
40
240
40
Arial
13
QLineEdit{
background:rgb(114, 120, 149);
border: 2px solid rgb(152, 161, 199);
padding-left: 10px;
}
QLineEdit:hover{
background:rgb(114, 120, 149);
border: 2px solid rgb(181, 192, 236);
padding-left: 10px;
}
QLineEdit:focus{
background:rgb(114, 120, 149);
border: 2px solid rgb(255, 160, 6);
padding-left: 10px;
}
password
0
310
61
61
images/login.png images/login.png
90
160
41
41
images/user3.png
true
90
230
41
41
images/browser.png
true
150
130
241
261
images/id-card.png
true
0
0
541
191
Imprint MT Shadow
-1
50
false
false
QLabel{
background: none;
font: 50px "Imprint MT Shadow";
qproperty-alignment: AlignCenter;
}
MEMBER LOGIN
true
10
adminLoginContainer
QWidget{
border-radius: 15px;
background: rgb(107, 113, 140);
}
QWidget[accessibleName = adminLoginContainer]{
border: 5px solid rgb(38, 38, 38);
background: rgb(107, 113, 140);
}
0
240
540
370
Qt::LeftToRight
background:none;
QFrame::StyledPanel
QFrame::Raised
150
160
240
40
0
0
240
40
240
40
Arial
13
QLineEdit{
background:rgb(114, 120, 149);
border: 2px solid rgb(152, 161, 199);
padding-left: 10px;
}
QLineEdit:hover{
background:rgb(114, 120, 149);
border: 2px solid rgb(181, 192, 236);
padding-left: 10px;
}
QLineEdit:focus{
background:rgb(114, 120, 149);
border: 2px solid rgb(255, 160, 6);
padding-left: 10px;
}
username
150
230
240
40
0
0
240
40
240
40
Arial
13
QLineEdit{
background:rgb(114, 120, 149);
border: 2px solid rgb(152, 161, 199);
padding-left: 10px;
}
QLineEdit:hover{
background:rgb(114, 120, 149);
border: 2px solid rgb(181, 192, 236);
padding-left: 10px;
}
QLineEdit:focus{
background:rgb(114, 120, 149);
border: 2px solid rgb(255, 160, 6);
padding-left: 10px;
}
password
0
310
61
61
images/login.png images/login.png
90
160
41
41
images/user3.png
true
90
230
41
41
images/browser.png
true
150
130
241
261
background:none;
images/id-card.png
true
0
0
541
191
Imprint MT Shadow
-1
50
false
false
QLabel{
background: none;
font: 50px "Imprint MT Shadow";
qproperty-alignment: AlignCenter;
}
ADMINISTRATOR LOGIN
true
10
Pregunta hecha hace 3 años, 4 meses, 28 días - Por javajedi
2 Respuestas:
-
El problema que estás experimentando probablemente se deba a que el código generado en Python no está cargando correctamente el estilo de hoja de estilo CSS que has definido en el archivo .ui.
Asegúrate de que estás cargando el archivo de hoja de estilo correctamente en tu código Python. Puedes hacerlo de la siguiente manera:
- Importa la clase QApplication y el módulo QMainWindow en tu código Python:
python from PyQt5.QtWidgets import QApplication, QMainWindow
- Luego, después de cargar tu archivo .ui y convertirlo a código Python, crea una aplicación y una ventana principal:
python import sys from PyQt5.QtWidgets import QApplication, QMainWindow from PyQt5.uic import loadUi
app = QApplication(sys.argv) window = QMainWindow()
- Carga el archivo .ui y aplica el estilo de la hoja de estilo CSS:
python uifile = "tufichero.ui"
Reemplaza "tufichero.ui" con la ruta de tu archivo .ui
ui = loadUi(uifile) ui.setStyleSheet("your CSS style here")- Muestra la ventana principal:
python window.setCentralWidget(ui) window.show() sys.exit(app.exec_())
Asegúrate de que la ruta del archivo .ui esté correctamente especificada y de que estás aplicando el estilo de hoja de estilo CSS de la manera correcta. Con estos pasos, deberías poder cargar tu GUI con el estilo de hoja de estilo deseado. Si el problema persiste, revisa la consola de terminal para mensajes de error que puedan proporcionar más pistas sobre lo que está pasando.
Respondida el Dec 19, 2020 a las 04:49 - por Gpt
Votos positivos: 0 | Votos negativos: 0 -
There are a few potential reasons why your first page in the stacked widget might be losing its style sheet when running the Python script:
StyleSheet Not Applied to the Correct Element:
Ensure that the style sheet is applied to the correct QWidget. In your case, it should be applied to the
titleWindowContainer
QWidget within thetitleWindow
QWidget. Check if the style sheet is applied to the wrong element or if there is a naming conflict.Overriding Style Sheet in Python:
When you convert the Qt Designer UI file to Python, the style sheet information is embedded in the generated code. However, if you are manually overriding the style sheet in your Python script, it can overwrite the embedded style sheet. Check if you are setting a custom style sheet in your Python code and ensure that it does not interfere with the embedded style sheet.
Platform-Specific Style Issues:
Qt style sheets can sometimes behave differently across different platforms. If you are running the application on a different platform from where you designed the UI, there could be some platform-specific style issues. Try running the application on the same platform where you designed the UI to see if the style issue persists.
Incorrect UI File:
Make sure that the UI file you are loading in Python is the same one that you designed in Qt Designer. If you have made any changes to the UI file after converting it to Python, it could lead to style sheet discrepancies.
Here are some additional tips for troubleshooting:
Use a Qt debugging tool like Qt Creator to inspect the style sheet of the problematic widget. Check if there are any errors or warnings in the Python console related to style sheets or widget initialization. Try setting the style sheet programmatically in your Python code instead of using the embedded style sheet. If all else fails, try recreating the UI from scratch in Qt Designer and converting it to Python again.
Respondida el Dec 19, 2020 a las 04:55 - por Gemini
Votos positivos: 0 | Votos negativos: 0