Reputation: 966
Standard layout tabs from left to right. All tabs are nearby.
How to change the position of the one tab, so that it was attached to the right edge? Like This:
Is it possible to do?
Upvotes: 4
Views: 6600
Reputation: 730
You might want to insert an empty widget, before the last one and then disable it and set it to transparent. That achieves what you want. Attaching an example code for that.
from PyQt4 import QtGui
import sys
def main():
app = QtGui.QApplication(sys.argv)
tabW = QtGui.QTabWidget()
tabW.setStyleSheet("QTabBar::tab:disabled {"+\
"width: 300px;"+\
"color: transparent;"+\
"background: transparent;}")
pushButton1 = QtGui.QPushButton("QPushButton 1")
pushButton2 = QtGui.QPushButton("QPushButton 2")
tab1 = QtGui.QWidget()
tab2 = QtGui.QWidget()
emptySpace = QtGui.QWidget()
tab3 = QtGui.QWidget()
vBoxlayout = QtGui.QVBoxLayout()
vBoxlayout.addWidget(pushButton1)
vBoxlayout.addWidget(pushButton2)
#Resize width and height
tabW.resize(500, 500)
#Set Layout for Third Tab Page
tab3.setLayout(vBoxlayout)
tabW.addTab(tab1,"Tab 1")
tabW.addTab(tab2,"Tab 2")
tabW.addTab(emptySpace,"ES")
tabW.setTabEnabled(2,False)
tabW.addTab(tab3,"Tab 3")
tabW.setWindowTitle('PyQt QTabWidget Add Tabs and Widgets Inside Tab')
tabW.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Upvotes: 8
Reputation: 1285
Yes, you can set it using the the style sheet.
from PyQt4.QtGui import *
style = """QTabWidget::tab-bar{
alignment: right;
}"""
class MyWidget(QTabWidget):
def __init__(self, parent=None):
super(MyWidget, self).__init__(parent)
self.mW1 = QWidget(self)
self.mW2 = QWidget(self)
self.addTab(self.mW1, "w1")
self.addTab(self.mW2, "w2")
self.setStyleSheet(style)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
w = MyWidget()
w.show()
app.exec_()
By the way, there is also a method
self.setTabPosition(QTabWidget.East)
this will display at East
Upvotes: -1