Seite 1 von 1

QScrollView

Verfasst: Donnerstag 7. August 2003, 19:39
von egge
Hi! :)

Ich bin gerade dabei eine GUI mit Python und Qt zu programmieren.

Ich hab ein QFrame in einem QWorkspace eingbunden, welches man mit der Maus bewegen kann. Ich möchte jetzt allerdings, dass wenn dieses QFrame sich aus dem Fenster bewegt, rechts und unten ein Scrollbalken erscheint.
Ich hab mir die Qt-Documentation angeschaut, allerdings hab ich keine Ahnung wie ich das in Python umsetzten soll. :cry:

Hat jemand vielleicht eine Idee oder ein Tipp?
Wer sich den Code dazu anschauen möchte, er ist bei QMouseEvent gepostet.

Gruß egge :wink:

Verfasst: Donnerstag 7. August 2003, 22:03
von hans
Ich hab mal versucht, den Code mit dem Designer zu erzeugen (nur Formular, Scrollbar und File / Exit Menü, sonst nichts). Dann die Datei (.ui) mit pyuic nach Pythoncode (.py) übersetzt.

Hier die UI Datei.

Code: Alles auswählen

<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
<class>Form1</class>
<widget class="QMainWindow">
    <property name="name">
        <cstring>Form1</cstring>
    </property>
    <property name="geometry">
        <rect>
            <x>0</x>
            <y>0</y>
            <width>600</width>
            <height>480</height>
        </rect>
    </property>
    <property name="caption">
        <string>Form1</string>
    </property>
    <widget class="QScrollBar">
        <property name="name">
            <cstring>scrollBar1</cstring>
        </property>
        <property name="geometry">
            <rect>
                <x>560</x>
                <y>0</y>
                <width>21</width>
                <height>420</height>
            </rect>
        </property>
        <property name="orientation">
            <enum>Vertical</enum>
        </property>
    </widget>
</widget>
<menubar>
    <property name="name">
        <cstring>menubar</cstring>
    </property>
    <item text="&File" name="fileMenu">
        <separator/>
        <separator/>
        <action name="fileExitAction"/>
    </item>
</menubar>
<toolbars>
</toolbars>
<actions>
    <action>
        <property name="name">
            <cstring>fileExitAction</cstring>
        </property>
        <property name="text">
            <string>Exit</string>
        </property>
        <property name="menuText">
            <string>E&xit</string>
        </property>
        <property name="accel">
            <string></string>
        </property>
    </action>
</actions>
<connections>
    <connection>
        <sender>fileExitAction</sender>
        <signal>activated()</signal>
        <receiver>Form1</receiver>
        <slot>close()</slot>
    </connection>
    <connection>
        <sender>scrollBar1</sender>
        <signal>valueChanged(int)</signal>
        <receiver>Form1</receiver>
        <slot>OnScrollbarChanged()</slot>
    </connection>
</connections>
<slots>
    <slot>OnScrollbarChanged()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
</UI>
Und das wurde durch pyuic daraus generiert.

Code: Alles auswählen

# Form implementation generated from reading ui file 'TScrollbar.ui'
#
# Created: Don Aug 7 22:50:57 2003
#      by: The PyQt User Interface Compiler (pyuic)
#
# WARNING! All changes made in this file will be lost!


from qt import *


class Form1(QMainWindow):
    def __init__(self,parent = None,name = None,fl = 0):
        QMainWindow.__init__(self,parent,name,fl)
        self.statusBar()

        if not name:
            self.setName("Form1")


        self.setCentralWidget(QWidget(self,"qt_central_widget"))

        self.scrollBar1 = QScrollBar(self.centralWidget(),"scrollBar1")
        self.scrollBar1.setGeometry(QRect(560,0,21,420))
        self.scrollBar1.setOrientation(QScrollBar.Vertical)

        self.fileExitAction = QAction(self,"fileExitAction")




        self.menubar = QMenuBar(self,"menubar")

        self.fileMenu = QPopupMenu(self)
        self.fileMenu.insertSeparator()
        self.fileMenu.insertSeparator()
        self.fileExitAction.addTo(self.fileMenu)
        self.menubar.insertItem("",self.fileMenu,0)



        self.languageChange()

        self.resize(QSize(600,480).expandedTo(self.minimumSizeHint()))

        self.connect(self.fileExitAction,SIGNAL("activated()"),self,SLOT("close()"))
        self.connect(self.scrollBar1,SIGNAL("valueChanged(int)"),self.OnScrollbarChanged)

    def languageChange(self):
        self.setCaption(self.tr("Form1"))
        self.fileExitAction.setText(self.tr("Exit"))
        self.fileExitAction.setMenuText(self.tr("E&xit"))
        self.fileExitAction.setAccel(QString.null)
        self.menubar.findItem(0).setText(self.tr("&File"))

    def OnScrollbarChanged(self):
        print "Form1.OnScrollbarChanged(): Not implemented yet"
Hilft dir das schon weiter?

Hans