Home »
Python
PyQt MCQs
PyQt is a GUI widget toolkit that was developed by the British firm Riverbank Computing. It is a Python interface for Qt which is a popular cross-platform GUI library. PyQt supports a large set of modules, classes, and functions to work with the graphical user interface as well as files and directories, XML, Images, databases, and many more.
PyQt MCQs: This section contains multiple-choice questions and answers on PyQt. These MCQs are written for beginners as well as advanced, practice these MCQs to enhance and test the knowledge of PyQt.
List of PyQt MCQs
1. What is PyQt?
- GUI widgets toolkit
- CUI widgets toolkit
- Python Mathematics library for scientific purposes
- Python Mathematics library for quantity management
Answer: A) GUI widgets toolkit
Explanation:
Python PyQt is a Graphical User Interface (GUI) widgets toolkit i.e., you can say PyQt is an interface for Qt n Python.
Discuss this question
2. Which module contains non-GUI functionalities to work with the files and directories in Python?
- QtCui
- PyQtCui
- QtCore
- QtGui
Answer: C) QtCore
Explanation:
There is a module named QtCore in PyQt that provides the classes and functions for working with the files and directories in Python.
Discuss this question
3. The ____ class provides a dialog widget for specifying colors.
- QtColorDialog
- QColorDialog
- QtColors
- QColors
Answer: B) QColorDialog
Explanation:
In PyQt, the QColorDialog class provides a dialog widget for specifying colors.
Discuss this question
4. Which module contains GUI functionalities to work with the graphical interface in Python?
- QtGraphical
- PyQtGui
- QtCore
- QtGui
Answer: D) QtGui
Explanation:
There is a module named QtGui in PyQt that provides the classes and functions for working with the graphical interface in Python.
Discuss this question
5. Which is the correct import statement to import QtGui Module?
- from PyQt4 import PyQtGui
- from PyQt4 import QtGui
- import PyQt4 from QtGui
- Both A and B
Answer: B) from PyQt4 import QtGui
Explanation:
The correct import statement to import QtGui Module in Python is:
from PyQt4 import QtGui
Discuss this question
6. Which function is used for defining the size and position of a window in PyQt?
- setgeometry()
- setGeometry()
- getSetGeometry()
- set_Geometry()
Answer: B) setGeometry()
Explanation:
PyQt's method setGeometry() is used to define the size and position of the Window.
Syntax:
window.setGeometry(x, y, width, height)
Discuss this question
7. Which class is used for rendering and editing HTML in PyQt?
- QtWebKit
- QtGuiWebKit
- QtHtml
- Both B and C
Answer: A) QtWebKit
Explanation:
PyQt's class QtWebKit is used for rendering and editing HTML. The QtWebKit is one of the major engines to render webpages and execute JavaScript code.
Discuss this question
8. Which class is used for network programming in PyQt?
- QtNet
- QtNetworking
- QtNetwork
- QtNetworkProgramming
Answer: C) QtNetwork
Explanation:
The PyQt's class QtNetwork is used for network programming. The QtNetwork class provides the functionalities (classes, methods, and set of APIs) for programming applications that use TCP/IP operations such as requests, cookies, and sending data over HTTP.
Discuss this question
9. Which is/are the popular method(s) of QBoxLayout class in PyQt?
- addWidget()
- addStretch()
- addLayout()
- All of the above
Answer: D) All of the above
Explanation:
All of the given methods of the QBoxLayout class. They are used for various purposes such as the addWidget() method is used to add a widget to the BoxLayout, the addStretch() method is used to create an empty stretchable box, and the addLayout() method is used to add another nested layout.
Discuss this question
10. Which object acts as a placeholder to display non-editable text or image, or a movie of animated GIF in PyQt?
- QLabel
- QText
- QEditText
- QEditLabel
Answer: A) QLabel
Explanation:
A QLabel object acts as a placeholder to display non-editable text or image, or a movie of animated GIF.
Discuss this question
11. Which object(s)/widget(s) is/are used for drawing menus in QMainWindow?
- QMenuBar
- QMenu
- QAction
- All of the above
Answer: D) All of the above
Explanation:
The QMenuBar, QMenu, and QAction widgets are used for drawing menus in QMainWindow.
Discuss this question
12. Which function is used to create a popup menu in PyQt?
- addPopupMenu()
- createPopupMenu()
- createPmenu()
- QPopupMenu()
Answer: B) createPopupMenu()
Explanation:
In Python, PyQt API has a function named createPopupMenu() which is used for creating a popup menu.
Discuss this question
13. QMessageBox class is used to ____ in PyQt.
- Create message box
- Create popup box
- Send a message over TCP/IP
- All of the above
Answer: A) Create message box
Explanation:
QMessageBox class is used to create a message box in PyQt.
Discuss this question
14. PyQt was developed by which company?
- Riverbank Computing
- IBM
- Microsoft
- None of the above
Answer: A) Riverbank Computing
Explanation:
PyQt was developed by the british firm Riverbank computing.
Discuss this question
15. Which is the correct statement to set the position of a widget 'dispWin' to position x and y?
- dispWin.move(x, y)
- dispWin.windowMove(x, y)
- dispWin.setPosition(x, y)
- dispWin.position(x, y)
Answer: A) dispWin.move(x, y)
Explanation:
The correct code statement to set the position of a widget 'dispWin' to position x and y is:
dispWin.move(x, y)
Discuss this question
16. The getText() and setText() are the methods of ___ module.
- QtEditText
- QLineEdit
- QtLineEdit
- QtText
Answer: B) QLineEdit
Explanation:
The getText() and setText() are the methods of QLineEdit module. Where, the setText() is used for setting the text programmatically, and the getText() is used for getting the text.
Discuss this question
17. Which is the correct code statement to add an option in the menu in PyQt?
- menu.addNewMenu('option_name')
- menu.Add('option_name')
- menu.newMenu('option_name')
- menu.addMenu('option_name')
Answer: D) menu.addMenu('option_name')
Explanation:
The correct code statement to add an option in the menu in PyQt is:
menu.addMenu('option_name')
Where menu is the name of the menu bar and option_name is the new option to be added.
Discuss this question
18. Which class is used to align the widgets horizontally in PyQt?
- QtBoxLayout
- QHBoxLayout
- QtHBoxLayout
- PyQtHBoxLayout
Answer: B) QHBoxLayout
Explanation:
PyQt provides QHBoxLayout class which is used to arrange widgets in a horizontal box.
Discuss this question
19. Which class is used to align the widgets in two columns in PyQt?
- QFormLayout
- QLayout
- QTwoColumns
- None of the above
Answer: A) QFormLayout
Explanation:
PyQt provides QFormLayout class which is used to arrange widgets in two columns.
Discuss this question
20. Which class is used to align the widgets vertically in PyQt?
- QtBoxLayout
- QVBoxLayout
- QtVBoxLayout
- PyQtVBoxLayout
Answer: B) QVBoxLayout
Explanation:
PyQt provides QVBoxLayout class which is used to arrange widgets in a vertical box.
Discuss this question
21. Which is/are the layout manager class(s) in PyQt?
- QHBoxLayout
- QVBoxLayout
- QGridLayout
- QFormLayout
- All of the above
Answer: E) All of the above
Explanation:
There are four general-purpose layout manager classes in PyQt.
- QHBoxLayout class is used to arrange widgets in a horizontal box.
- QVBoxLayout class is used to arrange widgets in a vertical box.
- QGridLayout class is used to arrange widgets in a grid.
- QFormLayout class is used to arrange widgets in two columns.
Discuss this question
22. Which is the correct code statement to create a canvas in PyQt?
- self.image = QImage(self.size(), QImage.Format_RGB32)
- self.image = QImage()
- self.image = QImage(QImage.Format_RGB32, self.size())
- None of the above
Answer: A) self.image = QImage(self.size(), QImage.Format_RGB32)
Explanation:
The correct code statement to create a canvas in PyQt is:
self.image = QImage(self.size(), QImage.Format_RGB32)
Discuss this question
23. How to set or change the style to the spin box text in PyQt?
- font.setStyle()
- font.setStyle(style)
- font.style()
- font.style(style)
Answer: B) font.setStyle(style)
Explanation:
The font.setStyle() method can be used to set or change the style to the spin box text in PyQt. Consider the below code statement –
font.setStyle(QFont.StyleOblique)
Discuss this question
24. ___ method is used to set the database name in PyQt.
- setDatabaseName()
- setDbName()
- setDBName()
- QSetDatabaseName()
Answer: A) setDatabaseName()
Explanation:
The setDatabaseName() method is used to set the database name in PyQt.
Discuss this question
25. Which is/are the correct SQL driver(s) to work with PyQt?
- QDB2
- QIBASE
- QMYSQL
- QOCI
- All of the above
Answer: E) All of the above
Explanation:
All of the above are the correct SQL drivers to work with PyQt. Where QDB2 is used for IBM DB2, QIBASE is used for Borland InterBase Driver, QMYSQL is used for MySQL Driver, and QOCI is used for Oracle Call Interface Driver.
Discuss this question
26. Which driver is used for Microsoft SQL Server in PyQt?
- QMSSQL
- QMSDB2
- QODBC
- None of the above
Answer: C) QODBC
Explanation:
The QODBC is the SQL driver in PyQt which is an ODBC driver and is also used for Microsoft SQL Server.
Discuss this question
27. Which driver is used for SQLite version 3 or above in PyQt?
- QSQLITE3
- QSQLITE3x
- QSQLITE2
- QSQLITE
Answer: D) QSQLITE
Explanation:
The QSQLITE driver is used for SQLite version 3 or above. Whereas, QSQLITE2 is used for SQLite version 2.
Discuss this question
28. MDI stands for ____ in PyQt.
- Multiple Drawing Interface
- Multiple DialogBox Interface
- Multiple Document Interface
- None of the above
Answer: C) Multiple Document Interface
Explanation:
The MDI stands for Multiple Document Interface in PyQt.
Discuss this question
29. Which class provides access to a system-wide clipboard in PyQt?
- QtClipboard
- QClipboard
- PyQtClipboard
- QSysClipboard
Answer: B) QClipboard
Explanation:
PyQt has a class QClipboard that provides access to a system-wide clipboard for the various operations related to copy and paste.
Discuss this question
30. Which QClipboard class's method is used to copy QImage into the clipboard in PyQt?
- copyImage()
- copyQImage()
- setQImage()
- setImage()
Answer: D) setImage()
Explanation:
The setImage() is a method of QClipboard class that is used to copy a QImage into a clipboard in PyQt
Discuss this question