-1

I have a project that uses PyQt5 to create a GUI. I used StyleSheet to change the widget appearance. Everything is fine but there is only 1 thing It's not okay. It's about left and center margin of the text in the textbox. I tried looking on stackoverflow and the Qt forum but didn't see anyone who had a way to margin the text. This is image my GUI: GUI

This is my styleSheet:

QWidget{
background-color: rgb(0, 0, 0);
border-bottom-right-radius:10px;
border-top-right-radius:10px;
border-bottom-left-radius:10px;
border-top-left-radius:10px;
color: rgb(0, 0, 0);

}
QSpinBox {
color: rgb(0, 0, 0);
background-color: rgb(0, 0, 0);
border-bottom-right-radius:10px;
border-top-right-radius:10px;
border-bottom-left-radius:10px;
border-top-left-radius:10px;
color: rgb(255, 255, 255);
background-color: rgb(150, 150, 150);
font: 75 10pt "MS Shell Dlg 2";
}
QSpinBox::up-button {
width:20px;
     height:20px;
}
QSpinBox::down-button {
width:20px;
     height:20px;
}
QDoubleSpinBox {
color: rgb(0, 0, 0);
background-color: rgb(0, 0, 0);
border-bottom-right-radius:10px;
border-top-right-radius:10px;
border-bottom-left-radius:10px;
border-top-left-radius:10px;
color: rgb(255, 255, 255);
background-color: rgb(150, 150, 150);
font: 75 10pt "MS Shell Dlg 2";
}
QDoubleSpinBox::up-button {
width:20px;
     height:20px;
}
QDoubleSpinBox::down-button {
width:20px;
     height:20px;
}
QTextEdit{
border-bottom-right-radius:20px;
border-top-right-radius:20px;
border-bottom-left-radius:20px;
border-top-left-radius:20px;
background-color: rgb(150, 150, 150);
color: rgb(255, 255, 255);
}
QComboBox{
border-bottom-right-radius:5px;
border-top-right-radius:5px;
border-bottom-left-radius:5px;
border-top-left-radius:5px;
background-color: rgb(150, 150, 150);
color: rgb(255, 255, 255);
}

How to align the text in Qt with styleSheet? (I not good in english so i sorry if my question look weird)

Update: This is image my Textbox: enter image description here

5
  • Which text do you want to align? Your QLabel (tên khách hàng, số điện thoại, etc.) ? You would like to align them on the left and not on the right? Or is it the text in the button (xóa khách hàng, ...)? Or something else?
    – Pamputt
    Commented Jul 2 at 7:38
  • Have you try QTextEdit { margin-top: 0px; margin-bottom: 0px; margin-left: 10px; margin-right: 2px; } ?
    – Pamputt
    Commented Jul 2 at 7:48
  • Not working @Pamputt but thank.
    – Long96
    Commented Jul 2 at 10:33
  • Sorry but your question is unclear. What is the text you cannot align? Are you referring to the four QTextEdit selected in the second picture? If that's the case, then it seems that you want to use them as one line entry field, and using QTextEdit is wrong, since it's intended for formatted multi line text. Use QLineEdit, which provides the alignment property by default. Commented Jul 2 at 18:50
  • Also, unrelated but extremely important: 1. always use layout managers, never rely on fixed geometries; 2. avoid QWidget {} without specific selectors, otherwise it will be inherited by *all widgets and cause issues in complex ones: if you want to set properties for the central widget, then use the object name selector: in your case, it probably will be QWidget#centralwidget (but check the correct name in the object inspector, it's the top level widget of the main window). Commented Jul 2 at 18:52

1 Answer 1

0

Maybe you can try the following QSS QTextEdit{padding-left:5px;padding-top:5px;

1
  • it work,thank :))
    – Long96
    Commented Jul 3 at 3:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.