Getting Started with Qt 5 by Benjamin Baka

Getting Started with Qt 5 by Benjamin Baka

Author:Benjamin Baka [Benjamin Baka]
Language: eng
Format: epub
Tags: COM051070 - COMPUTERS / Programming Languages / C++, COM087020 - COMPUTERS / Desktop Applications / Design and Graphics, COM051460 - COMPUTERS / Programming / Mobile Devices
Publisher: Packt
Published: 2019-02-28T10:51:47+00:00


Add the following lines of code to the mainwindow.cpp file that defines the createIcons() method:

void MainWindow::createIcons() {

newIcon = QPixmap("new.png");

openIcon = QPixmap("open.png");

closeIcon = QPixmap("close.png");

clearIcon = QPixmap("clear.png");

}

The createIcons() method will pass instances of QPixmap to the members that were declared in mainwindow.h.

The definition of setupCoreWidgets() is as follows, in mainwindow.cpp:

void MainWindow::setupCoreWidgets() {

mainWidget = new QWidget();

centralWidgetLayout = new QVBoxLayout();

formLayout = new QGridLayout();

buttonsLayout = new QHBoxLayout();

nameLabel = new QLabel("Name:");

dateOfBirthLabel= new QLabel("Date Of Birth:");

phoneNumberLabel = new QLabel("Phone Number");

savePushButton = new QPushButton("Save");

newPushButton = new QPushButton("Clear All");

nameLineEdit = new QLineEdit();

dateOfBirthEdit = new QDateEdit(QDate::currentDate());

phoneNumberLineEdit = new QLineEdit();

// TableView

appTable = new QTableView();

model = new QStandardItemModel(1, 3, this);

appTable->setContextMenuPolicy(Qt::CustomContextMenu);

appTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); /** Note **/

model->setHorizontalHeaderItem(0, new QStandardItem(QString("Name")));

model->setHorizontalHeaderItem(1, new QStandardItem(QString("Date of Birth")));

model->setHorizontalHeaderItem(2, new QStandardItem(QString("Phone Number"))); appTable->setModel(model)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.