forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CenterText.py
53 lines (42 loc) · 1.31 KB
/
CenterText.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2022/09/03
@author: Irony
@site: https://pyqt.site https://github.com/PyQt5
@email: [email protected]
@file: CenterText.py
@description: 文字居中对齐
"""
import sys
try:
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QStyle, QVBoxLayout, QWidget
except ImportError:
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QApplication, QStyle, QVBoxLayout, QWidget
from Lib.CtComboBox import CtComboBox
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
layout = QVBoxLayout(self)
c1 = CtComboBox(self)
c1.addItems(['item-%s' % i for i in range(10)])
layout.addWidget(c1)
# 可编辑
c2 = CtComboBox(self)
c2.setEditable(True)
c2.lineEdit().setAlignment(Qt.AlignCenter)
c2.addItems(['item-%s' % i for i in range(10)])
layout.addWidget(c2)
# 带图标
c3 = CtComboBox(self)
for i in range(10):
c3.addItem(c3.style().standardIcon(QStyle.SP_ComputerIcon),
'item-%s' % i)
layout.addWidget(c3)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())