本文整理汇总了Python中PyQt5.QtWidgets.QTableView.show方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.show方法的具体用法?Python QTableView.show怎么用?Python QTableView.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.show方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WishlistForm
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
class WishlistForm(QDialog):
def __init__(self):
super(WishlistForm, self).__init__()
self.initUI(self)
def initUI(self, WishlistForm):
layout = QGridLayout(self)
self.show_wishlist_button = QPushButton("Show Wishlist")
layout.addWidget(self.show_wishlist_button, 0, 1, 1, 2)
self.setLayout(layout)
self.show_wishlist_button.clicked.connect(self.
show_wishlist_button_click)
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.setWindowTitle("Wishlist")
self.setWindowIcon(QIcon(QPixmap('../images/whish.png')))
def show_table(self, model):
self.table = QTableView()
self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.model = model
self.table.setWindowTitle("Wishlist")
self.table.setWindowIcon(QIcon(QPixmap('../images/icon.png')))
self.table.setModel(model)
self.table.show()
def show_wishlist_button_click(self):
text = 'Want Тo Read'
books = select_by_status(text)
if books == []:
QMessageBox(QMessageBox.Information, "No results",
"There are no books in the wishlist!").exec_()
return
else:
wishlist_model = BookModel()
books = [Book(*book) for book in books]
wishlist_model.set_books(books)
self.show_table(wishlist_model)
示例2: InstanceVM
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
class InstanceVM(object):
def __init__(self, model, parent, file_path):
self.file_path = os.path.abspath(file_path)
self.modified = False
self.model = model
self.table_vm = InstanceTableModel(model)
self.table_vm.modified.connect(self.set_dirty)
self.table_view = QTableView()
self.table_view.show()
self.table_view.closeEvent = self.close_handler
self.table_view.setModel(self.table_vm)
self.parent = parent
self.sub_window = parent.mdi.addSubWindow(self.table_view)
self.sub_window.instance = self
self.sub_window.setAttribute(Qt.WA_DeleteOnClose)
self.update_title()
parent.instances.append(self)
def set_dirty(self):
self.set_modified(True)
def set_modified(self, b):
self.modified = b
self.sub_window.setWindowModified(b)
def update_title(self):
self.sub_window.setWindowTitle(self.file_path + "[*]")
def close_handler(self, ev):
if self.modified:
ret = QMessageBox().question(
self.table_view, "Confirm",
"close without saving?",
QMessageBox.Yes | QMessageBox.No)
if ret == QMessageBox.No:
ev.ignore()
return
self.parent.remove_instance(self)
示例3: LibraryForm
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
class LibraryForm(QDialog):
def __init__(self):
super(LibraryForm, self).__init__()
self.initUI(self)
def initUI(self, LibraryForm):
layout = QGridLayout(self)
self.show_lib_button = QPushButton("Show Library")
layout.addWidget(self.show_lib_button, 0, 1, 1, 2)
self.setLayout(layout)
self.show_lib_button.clicked.connect(self.show_lib_button_click)
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.setWindowTitle("Library")
self.setWindowIcon(QIcon(QPixmap('../images/library.png')))
def show_table(self, model):
self.table = QTableView()
self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.model = model
self.table.setWindowTitle("Library")
self.table.setWindowIcon(QIcon(QPixmap('../images/icon.png')))
self.table.setModel(model)
self.table.show()
def show_lib_button_click(self):
books = select_all()
if books == []:
QMessageBox(QMessageBox.Information, "No results",
"There are no books in the library!").exec_()
return
else:
book_model = BookModel()
books = [Book(*book) for book in books]
book_model.set_books(books)
self.show_table(book_model)
示例4: QApplication
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
#self._parent._fileSave()
pass
if __name__ == "__main__":
import sys
from PyQt5.QtWidgets import QApplication, QTableView
from mtg.Database import CardDatabase
app = QApplication(sys.argv)
db = CardDatabase()
mdl = CubeModel(os.path.abspath(r".\MyCube.xml"), db, parent=app)
mdl._cubeData = etree.parse(mdl._cubeFile)
tbl = QTableView()
tbl.setModel(mdl)
tbl.resize(800, 600)
for i in range(mdl.columnCount()):
tbl.setColumnWidth(i, CARD_WIDTH)
for i in range(mdl.rowCount()):
tbl.setRowHeight(i, CARD_HEIGHT)
tbl.show()
sys.exit(app.exec_())
示例5: int
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
value = int(index.model().data(index, Qt.EditRole))
editor.setValue(value)
def setModelData(self, editor, model, index):
value = editor.value()
model.setData(index, value, Qt.EditRole)
def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect)
if __name__ == '__main__':
app = QApplication(sys.argv)
data = MyData()
table_view = QTableView()
my_model = MyModel(data)
table_view.setModel(my_model)
delegate = MyDelegate()
table_view.setItemDelegate(delegate)
table_view.show()
# The mainloop of the application. The event handling starts from this point.
# The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead.
exit_code = app.exec_()
# The sys.exit() method ensures a clean exit.
# The environment will be informed, how the application ended.
sys.exit(exit_code)
开发者ID:jeremiedecock,项目名称:snippets,代码行数:33,代码来源:widget_QTableView_delegate_on_edit_using_dial_widget.py
示例6: ShowItems_Form
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
class ShowItems_Form(QDialog):
def __init__(self):
super(ShowItems_Form, self).__init__()
self.setupUi(self)
def setupUi(self, ShowItems_Form):
layout = QGridLayout(self)
self.room_number_label = QLabel("Room Number:")
self.room_number_line_edit = QLineEdit()
self.item_label = QLabel("Choose Item:")
self.item_combo_box = QComboBox()
self.show_items = QPushButton("Show Items")
self.item_combo_box.addItems(ITEMS)
layout.addWidget(self.room_number_label, 0, 0)
layout.addWidget(self.room_number_line_edit, 0, 1)
layout.addWidget(self.item_label, 1, 0)
layout.addWidget(self.item_combo_box, 1, 1)
layout.addWidget(self.show_items, 2, 0, 1, 2, Qt.AlignCenter)
self.setLayout(layout)
self.show_items.clicked.connect(self.show_button_click)
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.setWindowIcon(QIcon(QPixmap('hotel_icon.jpg')))
self.setWindowTitle("Show Items")
def show_table(self, items, model):
self.table = QTableView()
self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.model = model
if type(model) == type(FurnituresModel()):
self.model.set_furnitures(items)
self.table.setWindowTitle("Furnitures")
elif type(model) == type(BathItemsModel()):
self.model.set_bath_items(items)
self.table.setWindowTitle("Bath Items")
elif type(model) == type(FoodModel()):
self.model.set_food(items)
self.table.setWindowTitle("Food")
elif type(model) == type(SleepingFurnituresModel()):
self.model.set_sleeping_furnitures(items)
self.table.setWindowTitle("Sleeping Furnitures")
self.table.setWindowIcon(QIcon(QPixmap(':/images/hotel_icon.jpg')))
self.table.setModel(model)
self.table.show()
def show_button_click(self):
room_number = self.room_number_line_edit.text()
item = self.item_combo_box.currentText()
if not Validations.is_positive_integer(room_number):
QMessageBox(QMessageBox.Critical, "Error",
"Invalid room number. Correct it!!!").exec_()
return
if not int(room_number) in get_all_rooms_number():
QMessageBox(QMessageBox.Critical, "Error",
"There is no room with such number." +
" Correct it!!!").exec_()
return
if item == 'Furnitures':
self.show_table(furnitures_in_room(int(room_number)),
FurnituresModel())
elif item == 'Bath Items':
self.show_table(bath_items_in_room(int(room_number)),
BathItemsModel())
elif item == 'Food':
self.show_table(food_in_room(int(room_number)),
FoodModel())
elif item == 'Sleeping Furnitures':
self.show_table(sleeping_furnitures_in_room(int(room_number)),
SleepingFurnituresModel())
示例7: GoodreadsOptionsForm
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
class GoodreadsOptionsForm(QDialog):
def __init__(self, user_id):
super(GoodreadsOptionsForm, self).__init__()
self.initUI(self)
self.user_id = user_id
def initUI(self, GoodreadsOptionsForm):
layout = QGridLayout(self)
self.main_label = QLabel("Please choose an option:")
self.search_combo_box = QComboBox()
self.search_combo_box.addItem("Read")
self.search_combo_box.addItem("Currently Reading")
self.search_combo_box.addItem("To-Read")
self.search_button = QPushButton("Search")
layout.addWidget(self.main_label, 0, 0)
layout.addWidget(self.search_combo_box, 0, 1)
layout.addWidget(self.search_button, 0, 2, 1, 2)
self.setLayout(layout)
self.search_button.clicked.connect(self.search_button_click)
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.setWindowTitle("Search Books")
self.setWindowIcon(QIcon(QPixmap('../images/search.png')))
def show_user_shelf(self, user_id, shelf):
goodreads_shelf = shelf
client = GoodReadsClient(KEY, SECRET)
books = client.get_shelf(user_id, goodreads_shelf)
view_books = []
for book in books:
isbn = book["isbn"]
title = book["title"]
goodreads_url = book["link"]
year = book["published"]
author = book["authors"][0]["name"]
rating = book["average_rating"]
view_books.append((isbn, title, author, year,
rating, goodreads_url))
if view_books != []:
book_model = GoodReadsBookModel()
view_books = [GoodReadsBook(*book) for book in view_books]
book_model.set_books(view_books)
self.show_table(book_model)
else:
QMessageBox(QMessageBox.Information, "No results",
"Sorry. There are no results found!").exec_()
def show_table(self, model):
self.table = QTableView()
self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.model = model
self.table.setWindowTitle("Books")
self.table.setWindowIcon(QIcon(QPixmap('../images/icon.png')))
self.table.setModel(model)
self.table.resizeColumnsToContents()
self.table.show()
def search_button_click(self):
option = self.search_combo_box.currentText()
shelf = ""
if option == 'Read':
shelf = "read"
elif option == 'Currently Reading':
shelf = "currently-reading"
elif option == 'To-Read':
shelf = "to-read"
self.show_user_shelf(self.user_id, shelf)
示例8: updateEditorGeometry
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
spinBox.interpretText()
value = spinBox.value()
model.setData(index, value, Qt.EditRole)
def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
model = QStandardItemModel(4, 2)
tableView = QTableView()
tableView.setModel(model)
delegate = SpinBoxDelegate()
tableView.setItemDelegate(delegate)
for row in range(4):
for column in range(2):
index = model.index(row, column, QModelIndex())
model.setData(index, (row + 1) * (column + 1))
tableView.setWindowTitle("Spin Box Delegate")
tableView.show()
sys.exit(app.exec_())
示例9: ShowClient_Form
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
class ShowClient_Form(QDialog):
def __init__(self):
super(ShowClient_Form, self).__init__()
self.setupUi(self)
def setupUi(self, ShowClient_Form):
layout = QGridLayout(self)
self.first_name_label = QLabel("First Name:")
self.first_name_line_edit = QLineEdit()
self.last_name_label = QLabel("Last Name:")
self.last_name_line_edit = QLineEdit()
self.show_client = QPushButton("Show Client")
layout.addWidget(self.first_name_label, 0, 0)
layout.addWidget(self.first_name_line_edit, 0, 1)
layout.addWidget(self.last_name_label, 1, 0)
layout.addWidget(self.last_name_line_edit, 1, 1)
layout.addWidget(self.show_client, 2, 0, 1, 2, Qt.AlignCenter)
self.setLayout(layout)
self.show_client.clicked.connect(self.show_button_click)
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.setWindowIcon(QIcon(QPixmap('hotel_icon.jpg')))
self.setWindowTitle("Show Client")
def show_clients_model(self, clients, is_maid=False):
self.table = QTableView()
self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.model = ClientsModel(is_maid)
self.model.set_clients(clients)
self.table.setModel(self.model)
self.table.setWindowTitle('Show Client')
self.table.setWindowIcon(QIcon(QPixmap(':/images/hotel_icon.jpg')))
self.table.show()
def is_information_invalid(self, first_name, last_name):
return (not Validations.is_name(first_name) or
not Validations.is_name(last_name))
def error_message(self, first_name, last_name):
properties = [Validations.is_name, Validations.is_name]
data = [first_name, last_name]
messages = ['first name', 'last name']
result = []
for i in range(len(data)):
if not properties[i](data[i]):
result.append(messages[i] + ',')
return ' '.join(result)
def show_button_click(self):
first_name = self.first_name_line_edit.text()
last_name = self.last_name_line_edit.text()
if self.is_information_invalid(first_name, last_name):
error_message = self.error_message(first_name, last_name)
QMessageBox(QMessageBox.Critical, "Error",
"Invalid " + error_message[:len(error_message) - 1] +
". Correct it!!!").exec_()
return
if not show_client(first_name.capitalize(), last_name.capitalize()):
QMessageBox(QMessageBox.Warning, "Warning",
"This person is not a Client!!!").exec_()
return
self.show_clients_model(show_client(first_name.capitalize(),
last_name.capitalize()), True)
示例10: FreezeTableWidget
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
class FreezeTableWidget(QTableView):
def __init__(self, model):
super(FreezeTableWidget, self).__init__()
self.setModel(model)
self.frozenTableView = QTableView(self)
self.init()
self.horizontalHeader().sectionResized.connect(self.updateSectionWidth)
self.verticalHeader().sectionResized.connect(self.updateSectionHeight)
self.frozenTableView.verticalScrollBar().valueChanged.connect(
self.verticalScrollBar().setValue)
self.verticalScrollBar().valueChanged.connect(
self.frozenTableView.verticalScrollBar().setValue)
def init(self):
self.frozenTableView.setModel(self.model())
self.frozenTableView.setFocusPolicy(Qt.NoFocus)
self.frozenTableView.verticalHeader().hide()
self.frozenTableView.horizontalHeader().setSectionResizeMode(
QHeaderView.Fixed)
self.viewport().stackUnder(self.frozenTableView)
self.frozenTableView.setStyleSheet('''
QTableView { border: none;
background-color: #8EDE21;
selection-background-color: #999;
}''') # for demo purposes
self.frozenTableView.setSelectionModel(self.selectionModel())
for col in range(1, self.model().columnCount()):
self.frozenTableView.setColumnHidden(col, True)
self.frozenTableView.setColumnWidth(0, self.columnWidth(0))
self.frozenTableView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.frozenTableView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.frozenTableView.show()
self.updateFrozenTableGeometry()
self.setHorizontalScrollMode(self.ScrollPerPixel)
self.setVerticalScrollMode(self.ScrollPerPixel)
self.frozenTableView.setVerticalScrollMode(self.ScrollPerPixel)
def updateSectionWidth(self, logicalIndex, oldSize, newSize):
if self.logicalIndex == 0:
self.frozenTableView.setColumnWidth(0, newSize)
self.updateFrozenTableGeometry()
def updateSectionHeight(self, logicalIndex, oldSize, newSize):
self.frozenTableView.setRowHeight(logicalIndex, newSize)
def resizeEvent(self, event):
super(FreezeTableWidget, self).resizeEvent(event)
self.updateFrozenTableGeometry()
def moveCursor(self, cursorAction, modifiers):
current = super(FreezeTableWidget, self).moveCursor(cursorAction, modifiers)
if (cursorAction == self.MoveLeft and
self.current.column() > 0 and
self.visualRect(current).topLeft().x() <
self.frozenTableView.columnWidth(0)):
newValue = (self.horizontalScrollBar().value() +
self.visualRect(current).topLeft().x() -
self.frozenTableView.columnWidth(0))
self.horizontalScrollBar().setValue(newValue)
return current
def scrollTo(self, index, hint):
if index.column() > 0:
super(FreezeTableWidget, self).scrollTo(index, hint)
def updateFrozenTableGeometry(self):
self.frozenTableView.setGeometry(
self.verticalHeader().width() + self.frameWidth(),
self.frameWidth(), self.columnWidth(0),
self.viewport().height() + self.horizontalHeader().height())
示例11: SearchForm
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
class SearchForm(QDialog):
def __init__(self):
super(SearchForm, self).__init__()
self.initUI(self)
def initUI(self, SearchForm):
layout = QGridLayout(self)
self.search_label = QLabel("Search book by:")
self.search_combo_box = QComboBox()
self.search_combo_box.addItem("ISBN")
self.search_combo_box.addItem("Title")
self.search_combo_box.addItem("Author")
self.search_combo_box.addItem("Genre")
self.search_line_edit = QLineEdit()
self.search_button = QPushButton("Search")
layout.addWidget(self.search_label, 0, 0)
layout.addWidget(self.search_combo_box, 0, 1)
layout.addWidget(self.search_line_edit, 0, 2)
layout.addWidget(self.search_button, 0, 3, 1, 2)
self.setLayout(layout)
self.search_button.clicked.connect(self.search_button_click)
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.setWindowTitle("Search Book")
self.setWindowIcon(QIcon(QPixmap('../images/search.png')))
def show_table(self, model):
self.table = QTableView()
self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.model = model
self.table.setWindowTitle("Books")
self.table.setWindowIcon(QIcon(QPixmap('../images/icon.png')))
self.table.setModel(model)
self.table.show()
def search_button_click(self):
search = self.search_combo_box.currentText()
text = self.search_line_edit.text()
if search == 'ISBN':
if not(Validations.is_valid_isbn(text)):
QMessageBox(QMessageBox.Critical, "Error",
"Invalid ISBN. Please correct it!").exec_()
books = select_by_isbn(string.capwords(text))
elif search == 'Title':
books = select_by_title(string.capwords(text))
elif search == 'Author':
books = select_by_author(string.capwords(text))
elif search == 'Genre':
books = select_by_genre(string.capwords(text))
if books != []:
book_model = BookModel()
books = [Book(*book) for book in books]
book_model.set_books(books)
self.show_table(book_model)
else:
QMessageBox(QMessageBox.Information, "No results",
"Sorry. There are no results found!").exec_()
示例12: QApplication
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
from PyQt5.QtSql import QSqlQueryModel,QSqlDatabase,QSqlQuery
from PyQt5.QtWidgets import QTableView,QApplication
import sys
app = QApplication(sys.argv)
db = QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName("patientData.db")
db.open()
projectModel = QSqlQueryModel()
projectModel.setQuery("select * from patient",db)
projectView = QTableView()
projectView.setModel(projectModel)
projectView.show()
app.exec_()
示例13: createView
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import show [as 别名]
def createView(title, model):
global offset, views
view = QTableView()
views.append(view)
view.setModel(model)
view.setWindowTitle(title)
view.move(100 + offset, 100 + offset)
offset += 20
view.show()