如何使用qt使标签窗口从mac顶部滑动?

时间:2012-05-25 10:01:07

标签: macos qt pyqt

我正在使用带有tabbuttons和qmaindwindow的qt在mac中设计一个设置窗口。

我希望在单击qmainwindow工具栏中的相应选项卡按钮时显示一个从顶部滑动的选项卡窗口。 与mac系统首选项或vlc首选项滑动窗口操作相同。

希望有人知道要实现目标的方向吗?

提前致谢

滑动动作不起作用。事件我为qmainwindow中的每个选项卡尝试了QDialog。

from PyQt4 import QtGui
from PyQt4 import QtCore

class Ui_windo(QtGui.QMainWindow):

    def __init__(self,parent=None):
        QtGui.QMainWindow.__init__(self, parent)

        self.setObjectName("windo")
        self.resize(400, 300)
        self.toolbuttonGroup = QtGui.QButtonGroup()
        self.toolbuttonGroup.setObjectName("toolbuttonGroup")
        self.toolbuttonGroup.setExclusive(True)
        self.button0 = QtGui.QToolButton()
        self.button1 = QtGui.QToolButton()
        self.button2 = QtGui.QToolButton()
        self.tabbutton(self.button0, 'button0')
        self.tabbutton(self.button1, 'button1')
        self.tabbutton(self.button2, 'button2')

        _toolBar = self.addToolBar('test')
        _toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        _toolBar.addWidget(self.button0)
        _toolBar.addWidget(self.button1)
        _toolBar.addWidget(self.button2)
        self.setUnifiedTitleAndToolBarOnMac(True);

        QtCore.QObject.connect(self.button0, QtCore.SIGNAL('clicked()'), self.dialog0)
        QtCore.QObject.connect(self.button1, QtCore.SIGNAL('clicked()'), self.dialog1)
        QtCore.QObject.connect(self.button2, QtCore.SIGNAL('clicked()'), self.dialog2)

    def dialog0(self):
        self._dialog0 = QtGui.QDialog()
        self._button0=QtGui.QPushButton(self._dialog0)
        self._button0.setText('Main dialog 0')
        self._dialog0.setModal(True)
        self.setCentralWidget(self._dialog0)

    def dialog1(self):
        self._dialog1 = QtGui.QDialog()
        self._button1=QtGui.QPushButton(self._dialog1)
        self._button1.setText('I m from dialog1')
        self._dialog1.setModal(True)
        self.setCentralWidget(self._dialog1)

    def dialog2(self):
        self._dialog2 = QtGui.QDialog()
        self._button2=QtGui.QPushButton(self._dialog2)
        self._button2.setText('I m from dialog2')
        self._dialog2.setModal(True)
        self.setCentralWidget(self._dialog2)

    def tabbutton(self, tabButton, text):
        self.toolbuttonGroup.addButton(tabButton)
        tabButton.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        tabButton.setText(text)
        tabButton.setObjectName(text)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        tabButton.setIcon(icon)
        tabButton.setCheckable(True)

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    ui = Ui_windo()
    ui.show()
    sys.exit(app.exec_())

1 个答案:

答案 0 :(得分:0)

使用QDialog将父级设置为必须“向下滑动”的窗口。它会“自动化”