barcodefield.com

Using the Convenience Item Widgets in Java Encoding barcode code 128 in Java Using the Convenience Item Widgets




How to generate, print barcode using .NET, Java sdk library control with example project source code free download:
Using the Convenience Item Widgets using barcode writer for none control to generate, create none image in none applications. Microsoft .NET Compact Framework super(MainForm none for none , self).__init__(parent) listLabel = QLabel("&List") self.listWidget = QListWidget() listLabel.

setBuddy(self.listWidget) tableLabel = QLabel("&Table") self.tableWidget = QTableWidget() tableLabel.

setBuddy(self.tableWidget) treeLabel = QLabel("Tre&e") self.treeWidget = QTreeWidget() treeLabel.

setBuddy(self.treeWidget). For each conve nience view we create a label and set up a buddy to make keyboard navigation easier. The layout code is similar to what we have seen before, so we have omitted it and will concern ourselves only with the connections and with creating the data structure..

self.connect(s none for none elf.tableWidget, SIGNAL("itemChanged(QTableWidgetItem*)"), self.

tableItemChanged) self.connect(addShipButton, SIGNAL("clicked()"), self.addShip) self.

connect(removeShipButton, SIGNAL("clicked()"), self.removeShip) self.connect(quitButton, SIGNAL("clicked()"), self.

accept) self.ships = ships.ShipContainer(QString("ships.

dat")) self.setWindowTitle("Ships (dict)"). By default, li st widgets are not editable, so all users can do is select an item. This is also true of tree widgets. But table widgets are editable by default, with users able to initiate editing by pressing F2 or by double-clicking a cell.

We can exercise full control over whether a view widget is editable using QAbstractItemView.setEditTriggers(); so, for example, we can make tables read-only or lists editable. This application allows users to edit ship data in the table, and to add and remove ships.

It also keeps all three views up-to-date by repopulating them after the data is loaded, and whenever a change occurs.. def populateLi none none st(self, selectedShip=None): selected = None self.listWidget.clear() for ship in self.

ships.inOrder(): item = QListWidgetItem(QString("%1 of %2/%3 (%L4)") \ .arg(ship.

name).arg(ship.owner).

arg(ship.country) \ .arg(ship.

teu)) self.listWidget.addItem(item) if selectedShip is not None and selectedShip == id(ship):.

14. Model/View Programming selected = ite none none m if selected is not None: selected.setSelected(True) self.listWidget.

setCurrentItem(selected). This method, l ike the other populating methods, is used both to populate the widget and to select the item that corresponds to the selectedShip a Ship s id() if one is passed in. We begin by clearing the widget. Then we iterate over every ship in the ships container.

The inOrder() method is provided by our custom ShipContainer class. For each ship we create a single list widget item that holds a single string. We use QString.

arg() so that we can use %L to show the TEUs with the appropriate digit separators (e.g., commas).

If we reach a list widget item that is showing the selected ship, we keep a reference to the item in selected, and after the list widget has been populated, we make the selected item both current and selected.. def populateTa none for none ble(self, selectedShip=None): selected = None self.tableWidget.clear() self.

tableWidget.setSortingEnabled(False) self.tableWidget.

setRowCount(len(self.ships)) headers = ["Name", "Owner", "Country", "Description", "TEU"] self.tableWidget.

setColumnCount(len(headers)) self.tableWidget.setHorizontalHeaderLabels(headers).

QString .arg(). 402 . The populate t able method is quite similar to the populate list method. We begin by clearing the table this clears both the cells and the vertical and horizontal headers (the row numbers and column titles). We then set the number of rows and columns, as well as the column titles.

We want users to be able to click a column to have the table sort by that column s contents. This functionality is built into QTableWidget, but it must be switched off before populating the table. We will switch sorting back on once the table is populated.

. for row, ship none none in enumerate(self.ships): item = QTableWidgetItem(ship.name) item.

setData(Qt.UserRole, QVariant(long(id(ship)))) if selectedShip is not None and selectedShip == id(ship): selected = item self.tableWidget.

setItem(row, ships.NAME, item) self.tableWidget.

setItem(row, ships.OWNER, QTableWidgetItem(ship.owner)).

In Qt 4.0 and 4.1, forgetting to switch off sorting before repopulating a table is harmless, but from Qt 4.

2 it must be done.. Using the Convenience Item Widgets self.tableWidg et.setItem(row, ships.

COUNTRY, QTableWidgetItem(ship.country)) self.tableWidget.

setItem(row, ships.DESCRIPTION, QTableWidgetItem(ship.description)) item = QTableWidgetItem(QString("%L1") \ .

arg(ship.teu, 8, 10, QChar(" "))) item.setTextAlignment(Qt.

AlignRight. Qt.AlignVCente none none r) self.tableWidget.

setItem(row, ships.TEU, item) self.tableWidget.

setSortingEnabled(True) self.tableWidget.resizeColumnsToContents() if selected is not None: selected.

setSelected(True) self.tableWidget.setCurrentItem(selected).

For each ship we must create a separate table item for each cell in the row that is used to show its data. The column indexes, NAME, OWNER, and so on, are integers from the ships module. In the rst item of each row we set the text (the ship s name) and, as user data, the ship s ID.

Storing the ID gives us a means of going from a table item to the ship that the item s row represents. This works because the ShipContainer is a dictionary whose keys are ship IDs and whose values are ships. For simple text items we can usually create the item and insert it into the table in a single statement: We have done this for the owner, country, and description attributes.

But if we want to format the item or store user data in it, we must create the item separately, then call its methods, and nally put it in the table with setItem(). We used this second approach to store the ships IDs as user data, and to right-align the TEU values. The TEU values are integers, and the QString.

arg() method used takes four arguments: an integer, a minimum eld width, a number base, and a character to pad with, should padding be necessary to reach the minimum eld width. Once the table is populated we switch sorting back on, resize each column to the width of its widest cell, and make the selected item (if any) current and selected. Populating lists and tables is very similar because they both use a rows-andcolumns approach.

Populating trees is quite different because we must use a parents-and-children approach. The tree view of the ships data has two columns. The rst column is the tree with the root items being countries, the next level items being owners, and the bottom-level items being the ships themselves.

The second column shows just the TEUs. We could have added a third column to show the descriptions, but doing so does not make any difference in terms of understanding how the tree widget works..

def populateTr none none ee(self, selectedShip=None): selected = None self.treeWidget.clear().

Copyright © barcodefield.com . All rights reserved.