Active Topics

 


Reply
Thread Tools
caco3's Avatar
Posts: 560 | Thanked: 423 times | Joined on May 2010 @ Switzerland
#1
Hi all

I need some help with a QScrollArea in Python (PyQt).
I made a window in QT Designer for my application and would like to have a scrollable area with all the buttons and so on inside.
I can see the scrollable area, but it does not scroll, even it is hiding some of the objects.
Could somebody have a look on the code below (main.py) and Ui_ConfigWindow.py, generated from QT Designer .ui file) and help me with telling what the missing code piece is?

Thanks a lot!

main.py:
Code:
#!/usr/bin/env python

import sys

from PyQt4.QtCore import * 
from PyQt4.QtGui import * 

from Ui_ConfigWindow import *
  
#####################################################
## Main function
#####################################################
def main():
    global app,  ConfigWindow
   
    app = QApplication(sys.argv)
    ConfigWindow = frmConfigWindow()
    ConfigWindow.show()

    sys.exit(app.exec_())


#####################################################
## Class for Configuration Window
#####################################################
class frmConfigWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        
        self.ui = Ui_ConfigWindow()
        self.ui.setupUi(self)
    
#####################################################
main() # Now we can start it.


Ui_ConfigWindow.py:
Code:
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '/home/gruinelli/Maemo/SleepAnalyser/N900/ConfigWindow.ui'
#
# Created: Sun Aug 22 14:06:27 2010
#      by: PyQt4 UI code generator 4.7.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_ConfigWindow(object):
    def setupUi(self, ConfigWindow):
        ConfigWindow.setObjectName("ConfigWindow")
        ConfigWindow.resize(800, 440)
        ConfigWindow.setSizeIncrement(QtCore.QSize(0, 0))
        self.centralwidget = QtGui.QWidget(ConfigWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.lblIcon = QtGui.QLabel(self.centralwidget)
        self.lblIcon.setGeometry(QtCore.QRect(660, 10, 117, 128))
        self.lblIcon.setText("")
        self.lblIcon.setPixmap(QtGui.QPixmap("img/SleepAnalyser.png"))
        self.lblIcon.setScaledContents(True)
        self.lblIcon.setObjectName("lblIcon")
        self.scrollArea = QtGui.QScrollArea(self.centralwidget)
        self.scrollArea.setGeometry(QtCore.QRect(0, 0, 651, 421))
        self.scrollArea.setFrameShape(QtGui.QFrame.StyledPanel)
        self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setObjectName("scrollArea")
        self.scrollAreaWidgetContents = QtGui.QWidget(self.scrollArea)
        self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 628, 398))
        self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
        self.SlrDelayStart = QtGui.QSlider(self.scrollAreaWidgetContents)
        self.SlrDelayStart.setEnabled(True)
        self.SlrDelayStart.setGeometry(QtCore.QRect(250, 320, 211, 71))
        self.SlrDelayStart.setMaximum(120)
        self.SlrDelayStart.setOrientation(QtCore.Qt.Horizontal)
        self.SlrDelayStart.setObjectName("SlrDelayStart")
        self.cSilentProfile = QtGui.QCheckBox(self.scrollAreaWidgetContents)
        self.cSilentProfile.setGeometry(QtCore.QRect(10, 80, 611, 71))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.cSilentProfile.setFont(font)
        self.cSilentProfile.setObjectName("cSilentProfile")
        self.lblUserName = QtGui.QLabel(self.scrollAreaWidgetContents)
        self.lblUserName.setGeometry(QtCore.QRect(150, 230, 161, 71))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.lblUserName.setFont(font)
        self.lblUserName.setText("")
        self.lblUserName.setObjectName("lblUserName")
        self.lblDelayStart = QtGui.QLabel(self.scrollAreaWidgetContents)
        self.lblDelayStart.setEnabled(True)
        self.lblDelayStart.setGeometry(QtCore.QRect(150, 320, 91, 71))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.lblDelayStart.setFont(font)
        self.lblDelayStart.setObjectName("lblDelayStart")
        self.cOfflineMode = QtGui.QCheckBox(self.scrollAreaWidgetContents)
        self.cOfflineMode.setGeometry(QtCore.QRect(10, 10, 611, 71))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.cOfflineMode.setFont(font)
        self.cOfflineMode.setObjectName("cOfflineMode")
        self.cStopAfterAlarm = QtGui.QCheckBox(self.scrollAreaWidgetContents)
        self.cStopAfterAlarm.setGeometry(QtCore.QRect(10, 150, 611, 71))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.cStopAfterAlarm.setFont(font)
        self.cStopAfterAlarm.setObjectName("cStopAfterAlarm")
        self.label_7 = QtGui.QLabel(self.scrollAreaWidgetContents)
        self.label_7.setGeometry(QtCore.QRect(20, 230, 131, 71))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label_7.setFont(font)
        self.label_7.setObjectName("label_7")
        self.bEditUserName = QtGui.QPushButton(self.scrollAreaWidgetContents)
        self.bEditUserName.setGeometry(QtCore.QRect(320, 230, 141, 71))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.bEditUserName.setFont(font)
        self.bEditUserName.setIconSize(QtCore.QSize(24, 24))
        self.bEditUserName.setObjectName("bEditUserName")
        self.label_8 = QtGui.QLabel(self.scrollAreaWidgetContents)
        self.label_8.setEnabled(True)
        self.label_8.setGeometry(QtCore.QRect(20, 320, 131, 71))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label_8.setFont(font)
        self.label_8.setObjectName("label_8")
        self.plainTextEdit = QtGui.QPlainTextEdit(self.scrollAreaWidgetContents)
        self.plainTextEdit.setEnabled(True)
        self.plainTextEdit.setGeometry(QtCore.QRect(0, 540, 621, 91))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.plainTextEdit.setFont(font)
        self.plainTextEdit.setReadOnly(True)
        self.plainTextEdit.setObjectName("plainTextEdit")
        self.cSilentProfile_2 = QtGui.QCheckBox(self.scrollAreaWidgetContents)
        self.cSilentProfile_2.setGeometry(QtCore.QRect(10, 400, 611, 71))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.cSilentProfile_2.setFont(font)
        self.cSilentProfile_2.setObjectName("cSilentProfile_2")
        self.cSilentProfile_3 = QtGui.QCheckBox(self.scrollAreaWidgetContents)
        self.cSilentProfile_3.setGeometry(QtCore.QRect(10, 470, 611, 71))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.cSilentProfile_3.setFont(font)
        self.cSilentProfile_3.setObjectName("cSilentProfile_3")
        self.scrollArea.setWidget(self.scrollAreaWidgetContents)
        ConfigWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(ConfigWindow)
        QtCore.QMetaObject.connectSlotsByName(ConfigWindow)

    def retranslateUi(self, ConfigWindow):
        ConfigWindow.setWindowTitle(QtGui.QApplication.translate("ConfigWindow", "SleepAnalyser (Settings)", None, QtGui.QApplication.UnicodeUTF8))
        self.cSilentProfile.setText(QtGui.QApplication.translate("ConfigWindow", "Change to Silent Profile while recording", None, QtGui.QApplication.UnicodeUTF8))
        self.lblDelayStart.setText(QtGui.QApplication.translate("ConfigWindow", "120 sec", None, QtGui.QApplication.UnicodeUTF8))
        self.cOfflineMode.setText(QtGui.QApplication.translate("ConfigWindow", "Change to Offline Mode while recording", None, QtGui.QApplication.UnicodeUTF8))
        self.cStopAfterAlarm.setText(QtGui.QApplication.translate("ConfigWindow", "Stop recording after alarm occured", None, QtGui.QApplication.UnicodeUTF8))
        self.label_7.setText(QtGui.QApplication.translate("ConfigWindow", "User name:", None, QtGui.QApplication.UnicodeUTF8))
        self.bEditUserName.setText(QtGui.QApplication.translate("ConfigWindow", "Change", None, QtGui.QApplication.UnicodeUTF8))
        self.label_8.setText(QtGui.QApplication.translate("ConfigWindow", "Start delay:", None, QtGui.QApplication.UnicodeUTF8))
        self.plainTextEdit.setPlainText(QtGui.QApplication.translate("ConfigWindow", "More settings can be changed at your own risk in the file ~/.SleepAnalyer/SleepAnalyser.conf", None, QtGui.QApplication.UnicodeUTF8))
        self.cSilentProfile_2.setText(QtGui.QApplication.translate("ConfigWindow", "bla", None, QtGui.QApplication.UnicodeUTF8))
        self.cSilentProfile_3.setText(QtGui.QApplication.translate("ConfigWindow", "bla", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    ConfigWindow = QtGui.QMainWindow()
    ui = Ui_ConfigWindow()
    ui.setupUi(ConfigWindow)
    ConfigWindow.show()
    sys.exit(app.exec_())
Attached Files
File Type: zip Window_with_QScrollArea.zip (3.3 KB, 261 views)
__________________
On N9 check out this:
CacheMe 4 the N9, a geocaching client / MiniBible, a bible viewer / TheWord brings daily bible verses onto your phone / BatteryGraph to monitor the battery drainage / doublepress2unlock to unlock your phone with a double press onto the power button / GPRS Data Usage to monitor your GPRS data usage /
and more...

On N900 check out this: SleepAnalyser to analyse your sleep movements / PasswordMaker a for a password generator

Last edited by caco3; 2010-08-22 at 22:59.
 

The Following User Says Thank You to caco3 For This Useful Post:
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#2
under self.scrollarea = QtGui.QScrollArea(...) in ui_ConfigWindow.py

add :
scroller = self.scrollArea.property("kineticScroller").toPyOb ject()
scroller.setEnabled(True)

if you want an example in the method setupGui of KhweeteurPref class:
http://gitorious.org/khweeteur/khwee...ur/__init__.py

And the thread you could find if u ve used the search :

http://talk.maemo.org/showthread.php?t=60569

Last edited by Khertan; 2010-08-23 at 08:21.
 

The Following 3 Users Say Thank You to Khertan For This Useful Post:
caco3's Avatar
Posts: 560 | Thanked: 423 times | Joined on May 2010 @ Switzerland
#3
Hi Kerthan

Thank you for your quick response.

I tried it in the way you showed me, but it is still not scrollable.
I also played around with having another qwidget with a bigger size in the QscrollArea.
Also with your modifications, it would not run anymore outside a Maemo environment.
I found an example [1] that works on my Linux PC as well as on my N900, but I do not understand how it works and how I can adapt it for QT Designer code and a QMainWindow.

Also I think there should be a better way than modifying ui_ConfigWindow.py, as it is auto generated from QT Designer and would lose those changes every time I modify the gui.

I tried to run your example, I even downloaded the complete source code (master tar.gz), but it failed running as it misses the module khweeteur. Why is it not included in the package?

[1] http://stackoverflow.com/questions/1...with-this-code

P.S. I used the search function, and I also fond the mentioned thread, but they did not help me

Thank you for your help!
__________________
On N9 check out this:
CacheMe 4 the N9, a geocaching client / MiniBible, a bible viewer / TheWord brings daily bible verses onto your phone / BatteryGraph to monitor the battery drainage / doublepress2unlock to unlock your phone with a double press onto the power button / GPRS Data Usage to monitor your GPRS data usage /
and more...

On N900 check out this: SleepAnalyser to analyse your sleep movements / PasswordMaker a for a password generator
 

The Following User Says Thank You to caco3 For This Useful Post:
caco3's Avatar
Posts: 560 | Thanked: 423 times | Joined on May 2010 @ Switzerland
#4
Hi all

After a long time searching in the web I figured out that I have to define the Layout explicitly in QT Designer.
See: http://www.qtcentre.org/threads/2926...Area-Confusion

I am wondering why they could not have solved that better. It would have saved me several hours...


Anyway, it seems to work quite well, also on the N900.
@Khertan: I did not add your 2 code lines, but scrolling seems still o behave quite nice. Is it possible that it is activated by default and the code not needed?
__________________
On N9 check out this:
CacheMe 4 the N9, a geocaching client / MiniBible, a bible viewer / TheWord brings daily bible verses onto your phone / BatteryGraph to monitor the battery drainage / doublepress2unlock to unlock your phone with a double press onto the power button / GPRS Data Usage to monitor your GPRS data usage /
and more...

On N900 check out this: SleepAnalyser to analyse your sleep movements / PasswordMaker a for a password generator
 

The Following User Says Thank You to caco3 For This Useful Post:
fpp's Avatar
Posts: 2,853 | Thanked: 968 times | Joined on Nov 2005
#5
Originally Posted by Khertan View Post
under self.scrollarea = QtGui.QScrollArea(...) in ui_ConfigWindow.py
add :
scroller = self.scrollArea.property("kineticScroller").toPyOb ject()
scroller.setEnabled(True)
if you want an example in the method setupGui of KhweeteurPref class:
http://gitorious.org/khweeteur/khwee...ur/__init__.py
Thanks a lot for that example Khertan ! I'd been pulling my hair out on this scrollArea thing for ages...

However, after a lot of testing, I find that the "scroller" business is not really necessary. Setting a (large) minimum size on the scrollArea's widget, and (maybe) expanding size policies on both the scrollArea and widget, as in your setupGui method, seems to be enough.

The benefit is that this is all doable in Designer, with no need to modify the python UI file afterwards...
__________________
maemo blog
 

The Following User Says Thank You to fpp For This Useful Post:
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#6
In fact it s depends on object you put in your scrollarea ... if you put a QTextEdit like in KhtEditor (http://gitorious.org/khteditor) you need to use this crappy trick.

Ps:KhtEditor already have ctrl-d shortcut
 
fpp's Avatar
Posts: 2,853 | Thanked: 968 times | Joined on Nov 2005
#7
Originally Posted by Khertan View Post
In fact it s depends on object you put in your scrollarea ... if you put a QTextEdit like in KhtEditor (http://gitorious.org/khteditor) you need to use this crappy trick.
Ah, OK... that was not the case in my first test, but it will be in the next... so good to know !

Ps:KhtEditor already have ctrl-d shortcut
Nice that you remembered ! :-)

I really need to replace my old PyGTKEditor, I keep forgetting since it's not in the repos anymore...

EDIT: oh wait, actually it *is* in devel... i was just typing it wrong :-)
__________________
maemo blog

Last edited by fpp; 2010-09-05 at 16:33.
 
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#8
Originally Posted by fpp View Post
EDIT: oh wait, actually it *is* in devel... i was just typing it wrong :-)
Yep explaining people why HAM didn't update application even if there is new version in my repository was too borring. And the fact is also that only 2% of users installed my repository, the other was still reporting errors on old version of my softs.
 
fpp's Avatar
Posts: 2,853 | Thanked: 968 times | Joined on Nov 2005
#9
:-)

Stupid old HAM... is FAPMAN any better ?

Anyway, KhtEditor is already really nice... maybe it could use a pair of PgUp/PgDn icons on the toolbar, for those who don't have them remapped on the keyboard ?
__________________
maemo blog
 
Reply


 
Forum Jump


All times are GMT. The time now is 10:45.