2014-06-06 1 views
0

GTK +에서 Qt로 이동하려는 작은 애플리케이션을 파이썬으로 작성했습니다.GTK에서 Qt로 이동

GTK 버전의 그래픽 인터페이스는 기본적으로 전체 최상위 창을 채우는 탭 위젯 (gtk.Notebook)입니다. 탭 윈도우는 최상위 창으로 커지고 축소되며 완전히 채 웁니다.

은 GTK의 코드는 다음과 같습니다

... 
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
... 
self.notebook = gtk.Notebook() 
self.window.add(self.notebook) 
... 

Qt는 비슷한 일을하는 방법? 나는 단지 그것을 이해할 수 없다! GTK 코드의 경우 그래픽 도구를 사용하지 않았지만 지금은 Qt 디자이너를 사용하려고합니다.

JW

+0

내가 Qt는 디자이너에 대한 자습서를 읽고 제안,하지만 난 당신이 누락 된 단계이다 같은데요, Qt Designer에서 위젯/메인 윈도우 내에 탭 위젯을 배치 한 후에 위젯의 빈 부분을 마우스 오른쪽 버튼으로 클릭하고 레이아웃 -> 레이아웃을 수직으로 선택해야합니다. 그러면 화면 전체가 채워집니다. 마찬가지로 탭 위젯의 탭에 항목을 배치 할 때도 동일한 작업을 수행해야합니다. 이것은 QWidget, QMainWindow 등이 inbuilt 레이아웃을 가지고 있기 때문에 당신이 명시 적으로 자신의 것을 만들 필요가 없기 때문입니다. –

+0

고마워, 지금 생각해. – JWA

답변

0

이 당신이 기본 QTabWidget이 설정 얻을 것입니다 방법입니다

from PyQt4.QtCore import (Qt, SIGNAL) 
from PyQt4.QtGui import (QApplication, QDialog, 
     QVBoxLayout, QPushButton, QTabWidget, QWidget,) 

class Form(QWidget): 

    def __init__(self, parent=None): 
     super(Form, self).__init__(parent) 

     self.tabauto = QWidget() #set up 'auto' tab 
     self.tabman = QWidget() #set up 'manual' tab 
     self.tabs = QTabWidget() #set up tabs widget 

     self.ButtonM = QPushButton("Manual Button") 
     self.ButtonA = QPushButton("AUto Button") 

     layoutO = QVBoxLayout() #set overal layout 

     layoutA = QVBoxLayout() 
     layoutA.addWidget(self.ButtonA) 

     layoutM = QVBoxLayout() 
     layoutM.addWidget(self.ButtonM) 

     self.tabman.setLayout(layoutM) #Add manual layout to manual tab 
     self.tabauto.setLayout(layoutA) #Add automatic layout to automatic tab 
     self.tabs.addTab(self.tabauto, "Auto") #assign tabs with their layouts to the overall tab widget 
     self.tabs.addTab(self.tabman, "Manual") #assign tabs with their layouts to the overall tab widget 
     layoutO.addWidget(self.tabs) #add overall tab widget to overall layout 
     self.setLayout(layoutO) #make the overall layout visible 

app = QApplication(sys.argv) 
form = Form() 
form.show() 
app.exec_()