100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

INF2611 Revision

Beoordeling
4,5
(2)
Verkocht
9
Pagina's
33
Cijfer
A+
Geüpload op
21-10-2023
Geschreven in
2023/2024

INF2611 Revision. Detailed work, solutions, memos, notes, and explanations

Instelling
Vak

Voorbeeld van de inhoud

INF2611 Revision.

, Chapter Summaries Module: INF2611



Chapter 9 – Advanced Widgets

9.1. Displaying System Clock Time in LCD Format




 To display LCD‐like digits, you use the LCD Number widget, an instance of the QLCDNumber class.
 To perform a repetitive task, you use a timer. A timer is an instance of the QTimer class.
 To use, create an instance of QTimer and connect its timeout() signal to the slot that performs the
desired task.
 To fetch the system clock time and measure a span of elapsed time, you use the QTime class. The
returned info can be converted into text with the toString() method.


CLASS METHODS USE
QLCDNumber setMode() Change the base of the numbers (Hex, Dec, Oct, Bin).
display() Display the specified content as LCD digits.
value() Return the value displayed by the widget.
QTimer timeout()
start(n) Generate a timeout() at n millisecond intervals.
setSingleShot(true) Generate a timeout() signal only once.
singleShot(n) Generate a timeout() signal only once after n milliseconds.
QTime currentTime() Fetches the system’s clock time as a QTime object.
hour(), minute(), Return the number of hours, minutes, seconds or millisecs.
seconds(), msecs()
addSecs(), addMSecs() Return time after adding specified number of seconds/msecs.
secsTo(), msecsTo() Return the number between two times.

In the following example, an instance of QTimer is created with the name timer, and it’s timeout() signal is
connected to showlcd(), a function that is invoked every 1000 milliseconds.


import sys
from disptime import *

class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)

timer = QtCore.QTimer(self)
timer.timeout.connect(self.showlcd)
timer.start(1000)


_______________________________________________________________________________________
Page 1 of 32

, Chapter Summaries Module: INF2611

self.showlcd()

def showlcd(self):
time = QtCore.QTime.currentTime()
text = time.toString('hh:mm')
self.ui.lcdNumber.display(text)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())



 Conversion of ui file to py file: > pyuic4 filename.ui -o filename.py



9.2. Working With Calendar and Displaying Dates in Different Formats




 To display a monthly calendar, you use the Calendar widget, which is an instance of the
QCalendarWidget class. By default, current month and year are shown with days in abbreviated form
(Sun, Mon, Tue etc.). Weekends are marked in red and the first column day is Sunday.
 The date that is selected is returned as a QDate object. It reads the current date from the system clock.
 For displaying and editing dates, use the Date Edit widget, which is an instance of the QDateEdit class.


WIDGET PROPERTIES DESCRIPTION
Calendar minimumDate, maximumDate Used to specify the min/max date range.
selectionMode Set to NoSelection to prohibit user selection.
verticalHeaderFormat Set to NoVerticalHeader to remove week numbers.
gridVisible Set to True to turn on Calendar grid.
HorizontalHeaderFormat SingleLetterDayNames, ShortDatNames,
LongDayNames

Date Edit minimumDate, maximumDate


CLASS METHODS USE
QCalendarWidget selectedDate() Returns currently selected date, month, year.
monthShown()
yearShown()

_______________________________________________________________________________________
Page 2 of 32

, Chapter Summaries Module: INF2611

setFirstDayOfWeek() Set the day in the first column.
selectionChanged() Emits when the user selects another date.
QDateEdit setDate()
setDisplayFormat() Options: dd.MM.yyyy, MMM.d.yy, MMM.d.yyyy,
MMMM.d.yy

QDate currentDate() Returns system date as QDate object.
setDate() Sets a date by specifying year, month, day.
year(), month(), day() Returns the year, month or day from the date object.
dayOfWeek() Returns the day of the week from the date object.
addDays(), addMonths(), Adds the specified number and returns new date.
addYears()
daysTo() Return the number of days between two dates.
daysInMonth(),
daysInYear()
isLeapYear() Returns true or false.
toPyDate() Returns date as a string. Accepts a format parameter, for
example: dd.MM.yyyy
Options are d (1‐31), dd (01‐31), ddd (Mon, Tue, etc.),
dddd (Monday, Tuesday, etc.), M (1‐12), MM (01‐12), MMM
(Jan, Feb, etc.), MMMM (January, February, etc.), yy (00‐99),
yyyy (1999, etc.).


In the example, the selectionChanged() signal of the Calendar widget is connected to dispdate(), a function
which retrieves the user selected date through the selectedDate() method, and displays it in the Date Edit
widget through setDate(). Optional: set the date format using setDisplayFormat().


import sys
from dispcalendar import *

class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)

QtCore.QObject.connect(self.ui.calendarWidget,
QtCore.SIGNAL('selectionChanged()'), self.dispdate)

def dispdate(self):
self.ui.dateEdit.setDisplayFormat('MMM d yyyy')
self.ui.dateEdit.setDate(self.ui.calendarWidget.selectedDate())

if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())



_______________________________________________________________________________________
Page 3 of 32

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
21 oktober 2023
Aantal pagina's
33
Geschreven in
2023/2024
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

Beoordelingen van geverifieerde kopers

Alle 2 reviews worden weergegeven
4 maanden geleden

1 jaar geleden

4,5

2 beoordelingen

5
1
4
1
3
0
2
0
1
0
Betrouwbare reviews op Stuvia

Alle beoordelingen zijn geschreven door echte Stuvia-gebruikers na geverifieerde aankopen.

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
ExellentStudyResources Chamberlain College Of Nursing
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
1095
Lid sinds
4 jaar
Aantal volgers
917
Documenten
2076
Laatst verkocht
2 weken geleden

3,6

148 beoordelingen

5
66
4
19
3
31
2
4
1
28

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen