I'm trying to create Login Window, which has QLineEdit below QLabel, but the current QLabel taking too many space in Window, i don't know why, here is the picture :
QLabel { background-color: red; }
My Code :
self.text = QLabel("LOGIN")
# self.text.setStyleSheet("QLabel { background-color: red; color : white;margin-top: 50px;margin-bottom: 0px; }")
self.text.setAlignment(Qt.AlignCenter)
# self.text.setContentsMargins(0, 0, 0, 0)
# self.text.setGeometry(QRect(10,10,30,80))
font = QFont("Sans-Serif", 30)
self.text.setFont(font)
form = QLineEdit("Write my name here..")
form.setAlignment(Qt.AlignCenter)
# form.setAlignment(Qt.AlignHCenter)
self.layout = QVBoxLayout()
# self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.setSpacing(0)
self.layout.addWidget(self.text)
self.layout.addWidget(form)
self.layout.addWidget(self.button)
self.setLayout(self.layout)
I do not see the relationship between the code provided by the OP and the LOGIN window from which you want to copy the structure, so create the following code from scratch.
from PySide2 import QtCore, QtGui, QtWidgets
class LoginPage(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.image_label = QtWidgets.QLabel(alignment=QtCore.Qt.AlignCenter)
self.login_label = QtWidgets.QLabel(
text=self.tr("LOG IN"), alignment=QtCore.Qt.AlignCenter
)
self.email_username_lineedit = QtWidgets.QLineEdit(
placeholderText=self.tr("Email or username")
)
self.password_lineedit = QtWidgets.QLineEdit(
placeholderText=self.tr("Password"), echoMode=QtWidgets.QLineEdit.Password
)
self.enter_button = QtWidgets.QPushButton(self.tr("Enter"))
self.forgot_password_label = QtWidgets.QLabel(
self.tr("Forgot password?"), alignment=QtCore.Qt.AlignCenter
)
self.image_label.setPixmap(QtGui.QPixmap("so-icon.png"))
# font = self.
font = self.login_label.font()
font.setPointSize(30)
self.login_label.setFont(font)
self.login_label.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed
)
self.forgot_password_label.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed
)
lay = QtWidgets.QVBoxLayout(self)
lay.setSpacing(0)
lay.addWidget(self.image_label)
lay.addWidget(self.login_label)
lay.addWidget(self.email_username_lineedit)
lay.addWidget(self.password_lineedit)
lay.addWidget(self.enter_button)
lay.addWidget(self.forgot_password_label)
self.resize(320, 480)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = LoginPage()
w.show()
sys.exit(app.exec_())
Related
Currently, I have a nested QVBoxLayout in the first column of a QHBoxLayout, but no matter my changes to .setContentMargins or .setSpacing nothing changes in that first column.
import sys
import io
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import QWebEngineView
class MyApp(QWidget):
def __init__(self):
super().__init__()
# Main widget/window
self.setWindowTitle('Test')
self.window_width, self.window_height = 1600, 900
self.setMinimumSize(self.window_width, self.window_height)
layout = QHBoxLayout()
self.setLayout(layout)
leftside = QWidget()
leftlayout = QVBoxLayout()
# Creating textbox and adding to leftside GUI
lineEdit = QLineEdit()
leftlayout.addWidget(lineEdit)
leftlayout.addWidget(QPushButton('Placeholder'))
leftside.setLayout(leftlayout)
# Adding both widgets to main layout
testWidget = QWidget()
testWidget.setStyleSheet("background-color: blue")
layout.addWidget(leftside, 2)
layout.addWidget(testWidget, 8)
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyleSheet('''
QWidget {
font-size: 20px;
}
''')
myApp = MyApp()
myApp.show()
try:
sys.exit(app.exec_())
except SystemExit:
print('Closing Window...')
Leaves me with this result:
What I want:
Use addStretch() method:
class MyApp(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Test")
self.window_width, self.window_height = 1600, 900
self.setMinimumSize(self.window_width, self.window_height)
leftside = QWidget()
leftlayout = QVBoxLayout(leftside)
lineEdit = QLineEdit()
leftlayout.addWidget(lineEdit)
leftlayout.addWidget(QPushButton("Placeholder"))
leftlayout.addStretch()
testWidget = QWidget()
testWidget.setStyleSheet("background-color: blue")
layout = QHBoxLayout(self)
layout.addWidget(leftside)
layout.addWidget(testWidget, stretch=1)
I am creating a LoginWindow and am using QLineEdit in order to make a place for my users to enter their details. Right now, I'm focused on creating the GUI. As shown in the picture, I am not sure why the layout looks like that, considering how I have setAlignment to AlignCenter. This also goes for QPushButton. Is there a class I am not aware to fix this formatting issue?
import sys
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QLineEdit, QVBoxLayout
import time #For time sleep
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("MidiScribe - Login Window")
self.setFixedSize(800,800)
self.setStyleSheet("""background-color: crimson;
border-color: maroon;
border: 2.5px outset rgb(128, 128, 128);
border-radius: 3px;""")
container = QWidget()
self.setCentralWidget(container)
mainLayout = QVBoxLayout(container)
self.username = QLineEdit()
self.username.setFixedWidth(300)
self.username.setStyleSheet("""background-color: white;""")
mainLayout.addWidget(self.username)
self.username.setAlignment(QtCore.Qt.AlignCenter)
self.setLayout(mainLayout)
self.password = QLineEdit()
self.password.setFixedWidth(300)
self.password.setStyleSheet("""background-color: white""")
mainLayout.addWidget(self.password)
self.password.setAlignment(QtCore.Qt.AlignCenter)
self.setLayout(mainLayout)
self.loginbutton = QPushButton("Login")
self.loginbutton.setFixedSize(50,50)
self.loginbutton.setStyleSheet("QPushButton { background-color: lightcoral }"
"QPushButton:Hover { background-color: lightpink }"
"QPushButton:pressed { background-color: indianred }" )
mainLayout.addWidget(self.loginbutton)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
There are many solutions for this case, but among them is to use a container that has the minimum size to show all the widgets and that is established through a QGridLayout:
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("MidiScribe - Login Window")
self.setFixedSize(800, 800)
self.setStyleSheet(
"""background-color: crimson;
border-color: maroon;
border: 2.5px outset rgb(128, 128, 128);
border-radius: 3px;"""
)
self.username = QLineEdit(alignment=QtCore.Qt.AlignCenter)
self.username.setFixedWidth(300)
self.username.setStyleSheet("""background-color: white;""")
self.password = QLineEdit(alignment=QtCore.Qt.AlignCenter)
self.password.setFixedWidth(300)
self.password.setStyleSheet("""background-color: white""")
self.loginbutton = QPushButton("Login")
self.loginbutton.setFixedSize(50, 50)
self.loginbutton.setStyleSheet(
"QPushButton { background-color: lightcoral }"
"QPushButton:Hover { background-color: lightpink }"
"QPushButton:pressed { background-color: indianred }"
)
container = QWidget(objectName="container")
container.setStyleSheet("QWidget#container{border: none}")
container.setContentsMargins(0, 0, 0, 0)
lay = QVBoxLayout(container)
lay.addWidget(self.username, alignment=QtCore.Qt.AlignCenter)
lay.addWidget(self.password, alignment=QtCore.Qt.AlignCenter)
lay.addWidget(self.loginbutton, alignment=QtCore.Qt.AlignCenter)
container.setFixedSize(container.sizeHint())
central_widget = QWidget()
self.setCentralWidget(central_widget)
grid_layout = QGridLayout(central_widget)
grid_layout.addWidget(container, 1, 1)
Just do alignment for mainLayout:
mainLayout.addWidget(self.loginbutton, alignment=QtCore.Qt.AlignCenter)
mainLayout.setAlignment(QtCore.Qt.AlignCenter)
In nutshell, I have QTabWidget which contain tab1 and tab2. Each of tab1 and tab2 contains a QListWidget. I would like to use QScroller on each of the QListWidget.
Here is the code (The simplest version).:
import sys
from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QAbstractItemView, QScrollerProperties, QScroller, QVBoxLayout, QListWidget,
QTabWidget, QApplication, QLabel, QListWidgetItem)
from PyQt5.QtCore import Qt
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.resize(700, 300)
mainLayout = QVBoxLayout()
self.tabWidget = QTabWidget()
self.tabWidget.setStyleSheet("QTabBar::tab { height: 50px; width: 250px; }")
mainLayout.addWidget(self.tabWidget)
myBoxLayout = QHBoxLayout()
self.tabWidget.setLayout(myBoxLayout)
self.tab1 = WidgetTab1()
self.tab2 = WidgetTab2()
self.tabWidget.addTab(self.tab1, 'Tab1')
self.tabWidget.addTab(self.tab2, 'Tab2')
self.setLayout(mainLayout)
class WidgetTab1(QWidget):
def __init__(self):
super().__init__()
self.hbox = QHBoxLayout()
# Create the list
self.mylist = QListWidget()
self.mylist.setStyleSheet("QListWidget::item { border-bottom: 1px solid gray; }")
self.mylist.setFocusPolicy(Qt.NoFocus)
self.mylist.setSelectionMode(QAbstractItemView.NoSelection)
self.mylist.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.mylist.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
for i in range(20):
item = QListWidgetItem(self.mylist)
self.mylist.addItem(item)
self.mylist.setItemWidget(item, QLabel(str(i)))
self.sp = QScrollerProperties()
self.sp.setScrollMetric(QScrollerProperties.DragVelocitySmoothingFactor, 0.6)
self.sp.setScrollMetric(QScrollerProperties.MinimumVelocity, 0.0)
self.sp.setScrollMetric(QScrollerProperties.MaximumVelocity, 0.2)
self.sp.setScrollMetric(QScrollerProperties.AcceleratingFlickMaximumTime, 0.1)
self.sp.setScrollMetric(QScrollerProperties.AcceleratingFlickSpeedupFactor, 1.2)
self.sp.setScrollMetric(QScrollerProperties.SnapPositionRatio, 0.2)
self.sp.setScrollMetric(QScrollerProperties.MaximumClickThroughVelocity, 1)
self.sp.setScrollMetric(QScrollerProperties.DragStartDistance, 0.001)
self.sp.setScrollMetric(QScrollerProperties.MousePressEventDelay, 0.5)
self.scroller = QScroller.scroller(self.mylist.viewport())
self.scroller.setScrollerProperties(self.sp)
self.scroller.grabGesture(self.mylist.viewport(), QScroller.LeftMouseButtonGesture)
self.mylist.show()
self.hbox.addWidget(self.mylist)
self.setLayout(self.hbox)
class WidgetTab2(QWidget):
def __init__(self):
super().__init__()
self.hbox = QHBoxLayout()
# Create the list
self.mylist = QListWidget()
self.mylist.setStyleSheet("QListWidget::item { border-bottom: 1px solid gray; }")
self.mylist.setFocusPolicy(Qt.NoFocus)
self.mylist.setSelectionMode(QAbstractItemView.NoSelection)
self.mylist.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.mylist.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
for i in range(19, 0, -1):
item = QListWidgetItem(self.mylist)
self.mylist.addItem(item)
self.mylist.setItemWidget(item, QLabel(str(i)))
self.sp = QScrollerProperties()
self.sp.setScrollMetric(QScrollerProperties.DragVelocitySmoothingFactor, 0.6)
self.sp.setScrollMetric(QScrollerProperties.MinimumVelocity, 0.0)
self.sp.setScrollMetric(QScrollerProperties.MaximumVelocity, 0.2)
self.sp.setScrollMetric(QScrollerProperties.AcceleratingFlickMaximumTime, 0.1)
self.sp.setScrollMetric(QScrollerProperties.AcceleratingFlickSpeedupFactor, 1.2)
self.sp.setScrollMetric(QScrollerProperties.SnapPositionRatio, 0.2)
self.sp.setScrollMetric(QScrollerProperties.MaximumClickThroughVelocity, 1)
self.sp.setScrollMetric(QScrollerProperties.DragStartDistance, 0.001)
self.sp.setScrollMetric(QScrollerProperties.MousePressEventDelay, 0.5)
self.scroller = QScroller.scroller(self.mylist.viewport())
self.scroller.setScrollerProperties(self.sp)
self.scroller.grabGesture(self.mylist.viewport(), QScroller.LeftMouseButtonGesture)
self.mylist.show()
self.hbox.addWidget(self.mylist)
self.setLayout(self.hbox)
if __name__ == '__main__':
qApplication = QApplication(sys.argv)
window = MainWindow()
window.show()
qApplication.exec_()
The problem is, the QScroller only work in the first tab. For example, If I choose tab1 at first and scroll on it. Then I switch to tab2, the scroll on tab2 will not work. If I choose tab2 first and scroll on it. Then I switch to tab1, the scroll on tab1 will not work.
I also have tried to ungrabGesture every I switch the tab, but it does not work.
Am I implement the QScroller in the wrong way?
Thanks #G.M. for your comment.
I solve the problem by upgrading the PyQt version from 5.11.3 to 5.13.0
I have QButtons arranged as first row has four buttons and second row has five buttons.
My code is developed using PyQt5 in Python2.7.
from PyQt5 import QtCore, QtGui, QtWidgets
import cv2
import time
import face_recognition.api as face_recognition
class Thread(QtCore.QThread):
changePixmap = QtCore.pyqtSignal(QtGui.QImage)
scaled_size = QtCore.QSize(640, 480)
def run(self):
cap = cv2.VideoCapture(1)
cap.set(3,1280);
cap.set(4,1024);
time.sleep(2)
while True:
ret, frame = cap.read()
if ret:
r=1
face_locations=[]
rescaleSize=480
if(frame.shape[0] > 480 and frame.shape[1] > 640):
r = rescaleSize / float(frame.shape[0])
dim = (int(frame.shape[1] * r), rescaleSize)
face_locations = face_recognition.face_locations(cv2.resize(frame, dim, fx=0.0, fy=0.0))
else:
face_locations = face_recognition.face_locations(frame)
for face_location in face_locations:
top, right, bottom, left = face_location
cv2.rectangle(frame,(int(right/r),int(top/r)),(int(left/r),int(bottom/r)),(0,255,0),2)
rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
convertToQtFormat = QtGui.QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QtGui.QImage.Format_RGB888)
p = convertToQtFormat.scaled(self.scaled_size, QtCore.Qt.KeepAspectRatio)
self.changePixmap.emit(p)
def scaled(self, scaled_size):
self.scaled_size = scaled_size
class PlayStreaming(QtWidgets.QLabel):
reSize = QtCore.pyqtSignal(QtCore.QSize)
def __init__(self):
super(PlayStreaming, self).__init__()
self.initUI()
#QtCore.pyqtSlot(QtGui.QImage)
def setImage(self, image):
self.label.setPixmap(QtGui.QPixmap.fromImage(image))
def initUI(self):
self.setWindowTitle("Image")
# create a label
self.label = QtWidgets.QLabel(self)
th = Thread(self)
th.changePixmap.connect(self.setImage)
self.reSize.connect(th.scaled)
th.start()
lay = QtWidgets.QVBoxLayout(self)
lay.addWidget(self.label, alignment=QtCore.Qt.AlignCenter)
def resizeEvent(self, event):
self.reSize.emit(self.size())
class UIWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
super(UIWidget, self).__init__(parent)
# Initialize tab screen
self.tabs = QtWidgets.QTabWidget()
self.tab1 = QtWidgets.QWidget()
self.tab2 = QtWidgets.QWidget()
self.tab3 = QtWidgets.QWidget()
# Add tabs
self.tabs.addTab(self.tab1, "Face")
self.tabs.addTab(self.tab2, "Human")
self.tabs.addTab(self.tab3, "Vehicle")
# Create first tab
self.createGridLayout()
self.tab1.layout = QtWidgets.QVBoxLayout()
self.display = PlayStreaming()
self.tab1.layout.addWidget(self.display, stretch=1)
self.tab1.layout.addWidget(self.horizontalGroupBox)
self.tab1.setLayout(self.tab1.layout)
# Add tabs to widget
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.tabs)
def createGridLayout(self):
self.horizontalGroupBox = QtWidgets.QGroupBox("")
self.horizontalGroupBox.setStyleSheet("QGroupBox{ background-color: red; border: none;}")
layout = QtWidgets.QGridLayout()
layout.addWidget(QtWidgets.QPushButton('Test'),0,0)
layout.addWidget(QtWidgets.QPushButton('Run'),0,1)
layout.addWidget(QtWidgets.QPushButton('RescaleUp'),0,2)
layout.addWidget(QtWidgets.QPushButton('RescaleDown'),0,3)
layout.addWidget(QtWidgets.QPushButton('Set Faces'),1,0)
layout.addWidget(QtWidgets.QPushButton('FacePose'),1,1)
layout.addWidget(QtWidgets.QPushButton('Gender'),1,2)
layout.addWidget(QtWidgets.QPushButton('Age'),1,3)
layout.addWidget(QtWidgets.QPushButton('Recognize'),1,4)
self.horizontalGroupBox.setLayout(layout)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = UIWidget()
w.resize(1000, 800)
w.show()
sys.exit(app.exec_())
I like to make the first four buttons are equally spaced and the second fuve buttons are also equally spaced.
For that, changes are made as
class UIWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
super(UIWidget, self).__init__(parent)
# Initialize tab screen
self.tabs = QtWidgets.QTabWidget()
self.tab1 = QtWidgets.QWidget()
self.tab2 = QtWidgets.QWidget()
self.tab3 = QtWidgets.QWidget()
# Add tabs
self.tabs.addTab(self.tab1, "Face")
self.tabs.addTab(self.tab2, "Human")
self.tabs.addTab(self.tab3, "Vehicle")
# Create first tab
self.createGridLayout()
self.tab1.layout = QtWidgets.QVBoxLayout()
self.display = PlayStreaming()
self.tab1.layout.addWidget(self.display, stretch=1)
self.tab1.layout.addWidget(self.horizontalGroupBox)
self.tab1.layout.addWidget(self.horizontalGroupBox2)
self.tab1.setLayout(self.tab1.layout)
# Add tabs to widget
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.tabs)
def createGridLayout(self):
self.horizontalGroupBox = QtWidgets.QGroupBox("")
self.horizontalGroupBox.setStyleSheet("QGroupBox{ background-color: red; border: none;}")
layout = QtWidgets.QGridLayout()
layout.addWidget(QtWidgets.QPushButton('Test'),0,0)
layout.addWidget(QtWidgets.QPushButton('Run'),0,1)
layout.addWidget(QtWidgets.QPushButton('RescaleUp'),0,2)
layout.addWidget(QtWidgets.QPushButton('RescaleDown'),0,3)
self.horizontalGroupBox.setLayout(layout)
self.horizontalGroupBox2 = QtWidgets.QGroupBox("")
self.horizontalGroupBox2.setStyleSheet("QGroupBox{ background-color: red; border: none;}")
layout = QtWidgets.QGridLayout()
layout.addWidget(QtWidgets.QPushButton('Set Faces'),0,0)
layout.addWidget(QtWidgets.QPushButton('FacePose'),0,1)
layout.addWidget(QtWidgets.QPushButton('Gender'),0,2)
layout.addWidget(QtWidgets.QPushButton('Age'),0,3)
layout.addWidget(QtWidgets.QPushButton('Recognize'),0,4)
self.horizontalGroupBox2.setLayout(layout)
Then there is a gap in between two QGroupBoxes.
How can I make so that there is no gap and first row and second row have equally spaced buttons?
You must use 1 QVBoxLayout next to 2 QHBoxLayouts:
def createGridLayout(self):
self.horizontalGroupBox = QtWidgets.QGroupBox("")
self.horizontalGroupBox.setStyleSheet("QGroupBox{ background-color: red; border: none;}")
hlay1 = QtWidgets.QHBoxLayout()
hlay1.addWidget(QtWidgets.QPushButton('Test'))
hlay1.addWidget(QtWidgets.QPushButton('Run'))
hlay1.addWidget(QtWidgets.QPushButton('RescaleUp'))
hlay1.addWidget(QtWidgets.QPushButton('RescaleDown'))
hlay2 = QtWidgets.QHBoxLayout()
hlay2.addWidget(QtWidgets.QPushButton('Set Faces'))
hlay2.addWidget(QtWidgets.QPushButton('FacePose'))
hlay2.addWidget(QtWidgets.QPushButton('Gender'))
hlay2.addWidget(QtWidgets.QPushButton('Age'))
hlay2.addWidget(QtWidgets.QPushButton('Recognize'))
layout = QtWidgets.QVBoxLayout()
layout.addLayout(hlay1)
layout.addLayout(hlay2)
self.horizontalGroupBox.setLayout(layout)
The code below creates a QListWidget with QListWidgetItem assigned a thumb image.
I would appreciate if you show how to make a color border around of the QListWidgetItem
Here is the Photoshoped image showing a concept:
from PyQt4 import QtGui, QtCore
import sys, os
class MyClassItem(QtGui.QListWidgetItem):
def __init__(self, parent=None):
super(QtGui.QListWidgetItem, self).__init__(parent)
class ThumbListWidget(QtGui.QListWidget):
def __init__(self, type, parent=None):
super(ThumbListWidget, self).__init__(parent)
self.setIconSize(QtCore.QSize(64, 64))
class Dialog_01(QtGui.QMainWindow):
def __init__(self):
super(QtGui.QMainWindow,self).__init__()
self.listItems={}
myQWidget = QtGui.QWidget()
myBoxLayout = QtGui.QVBoxLayout()
myQWidget.setLayout(myBoxLayout)
self.setCentralWidget(myQWidget)
self.listWidgetA = ThumbListWidget(self)
for i in range(7):
listItemAInstance=MyClassItem()
name='A'+'%04d'%i
listItemAInstance.setText(name)
listItemAInstance.setBackgroundColor(QtCore.Qt.darkGray)
if i%2: listItemAInstance.setBackgroundColor(QtCore.Qt.gray)
icon=self.getIcon(name)
listItemAInstance.setIcon( icon )
self.listWidgetA.addItem(listItemAInstance)
listItemBInstance=MyClassItem()
name='B'+'%04d'%i
listItemBInstance.setText(name)
icon=self.getIcon(name)
listItemBInstance.setIcon( icon )
myBoxLayout.addWidget(self.listWidgetA)
def getIcon(self, name):
thumbpath=os.path.expanduser("~")+'/thumbs/' +name+'/'+name+'.jpg'
if not thumbpath: return
if not os.path.exists(os.path.dirname(thumbpath)):
os.makedirs(os.path.dirname(thumbpath))
img = QtGui.QImage(64, 64, QtGui.QImage.Format_RGB32)
img.fill(QtGui.QColor(96,96,96))
painter = QtGui.QPainter(img)
font = painter.font()
font.setBold(True)
font.setPointSize(18)
painter.setPen(QtGui.QColor('black'))
painter.setFont(font)
painter.drawText(img.rect(), QtCore.Qt.AlignCenter, name)
painter.end()
img.save(thumbpath, 'JPG')
icon = QtGui.QIcon( thumbpath )
pixmap = icon.pixmap(64, 64)
icon = QtGui.QIcon(pixmap)
return icon
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
dialog_1 = Dialog_01()
dialog_1.show()
dialog_1.resize(720,480)
sys.exit(app.exec_())
Every class that derives from QWidget supports CSS styling. What you could do is something such as:
lwi = QListWidget()
lwi.setStyleSheet("QListWidget::item { border: 0px solid red }")
For more info, see http://qt-project.org/doc/qt-4.8/qwidget.html#styleSheet-prop
You can also style your entire application, but apply a certain part of styling only to QListWidgetItem by putting it as a prefix.
C++ example I found:
app.setStyleSheet("QListWidget { background: red; } QListWidget::item { background: yellow; } QListWidget::item:selected { background: blue; }");