PyQt改变QWidget的方向从右到左
PyQt Change Direction of QWidget from right to left
我想使用 SetLyouatDirection 将小部件的方向从右更改为左,但不起作用
这是我的结果:
这是我的代码:
for item in listConcrdance:
c+=1
widgitItem = QtGui.QListWidgetItem()
widget = QtGui.QWidget()
widgetText=QtGui.QLabel(str(c)+". "+item[1]+" ("+self.process.convertNumberToNameOFSorat(item[0][1])+":"+item[0][2]+")")
widgetText.setLayoutDirection(QtCore.Qt.RightToLeft)
widgetLayout = QtGui.QHBoxLayout()
widgetLayout.addWidget(widgetText)
widgetLayout.setSizeConstraint(QtGui.QLayout.SetFixedSize)
widget.setLayout(widgetLayout)
self.listWidgetQuran.addItem(widgitItem)
widgitItem.setSizeHint(widget.sizeHint())
self.listWidgetQuran.setItemWidget(widgitItem, widget)
使用[your_label].setAlignment(QtCore.Qt.AlignRight)
:
from PyQt4 import QtCore
from PyQt4 import QtGui
class Widget(QtGui.QWidget):
def __init__(self, parent=None):
super(Widget, self).__init__(parent=parent)
self.verticalLayout = QtGui.QVBoxLayout(self)
self.listWidget = QtGui.QListWidget(self)
self.verticalLayout.addWidget(self.listWidget)
for item in range(10):
widgitItem = QtGui.QListWidgetItem(self.listWidget)
widget = QtGui.QWidget()
widgetText = QtGui.QLabel(str(item))
if item % 2 == 0:
widgetText.setAlignment(QtCore.Qt.AlignRight)
else:
widgetText.setAlignment(QtCore.Qt.AlignLeft)
widgetLayout = QtGui.QHBoxLayout()
widgetLayout.addWidget(widgetText)
widget.setLayout(widgetLayout)
widgitItem.setSizeHint(widget.sizeHint())
self.listWidget.setItemWidget(widgitItem, widget)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
输出:
我想使用 SetLyouatDirection 将小部件的方向从右更改为左,但不起作用 这是我的结果:
这是我的代码:
for item in listConcrdance:
c+=1
widgitItem = QtGui.QListWidgetItem()
widget = QtGui.QWidget()
widgetText=QtGui.QLabel(str(c)+". "+item[1]+" ("+self.process.convertNumberToNameOFSorat(item[0][1])+":"+item[0][2]+")")
widgetText.setLayoutDirection(QtCore.Qt.RightToLeft)
widgetLayout = QtGui.QHBoxLayout()
widgetLayout.addWidget(widgetText)
widgetLayout.setSizeConstraint(QtGui.QLayout.SetFixedSize)
widget.setLayout(widgetLayout)
self.listWidgetQuran.addItem(widgitItem)
widgitItem.setSizeHint(widget.sizeHint())
self.listWidgetQuran.setItemWidget(widgitItem, widget)
使用[your_label].setAlignment(QtCore.Qt.AlignRight)
:
from PyQt4 import QtCore
from PyQt4 import QtGui
class Widget(QtGui.QWidget):
def __init__(self, parent=None):
super(Widget, self).__init__(parent=parent)
self.verticalLayout = QtGui.QVBoxLayout(self)
self.listWidget = QtGui.QListWidget(self)
self.verticalLayout.addWidget(self.listWidget)
for item in range(10):
widgitItem = QtGui.QListWidgetItem(self.listWidget)
widget = QtGui.QWidget()
widgetText = QtGui.QLabel(str(item))
if item % 2 == 0:
widgetText.setAlignment(QtCore.Qt.AlignRight)
else:
widgetText.setAlignment(QtCore.Qt.AlignLeft)
widgetLayout = QtGui.QHBoxLayout()
widgetLayout.addWidget(widgetText)
widget.setLayout(widgetLayout)
widgitItem.setSizeHint(widget.sizeHint())
self.listWidget.setItemWidget(widgitItem, widget)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
输出: