Bibliography:
Table from [I], window system comparison.pdf
Interesting rules from [I], UI development.pdf:
1. Relieve short-rem memory
2. Rely on recognition, not recall 3. Provide visual cues. 4. Provide defaults, undo and redo. 5. Provide interface shortcuts. 6. Use real-world metaphors. 7. Use progressive disclosure. 8. Promote visual clarity. 9. Encourage exploration.
What is Qt?
Qt is a comprehensive C++ application development framework for creating cross-platform GUI applications using a "write once, compile anywhere" approach. The Qt framework first became publicly available in May 1995.
Qt comes with a set of tools:
How to build one source file in QtCreator?
http://stackoverflow.com/questions/1579908/compile-one-file-in-qt-creator
Build->Build File.
How to debug?
Install a debugger for the platform. It doesn't come out-of-the-box. https://doc.qt.io/qtcreator/creator-debugger-engines.html
What exrta feature of text editor in QtCreator exist?
Alt+mouse or Alt+shift -- multyline selector in text editor
Tools->Options->TextEditor->Display->Visulize whitespaces
What is signals&slots?
The signals and slots mechanism is fundamental to all Qt programming. It enables the application programmer to bind objects together
without the objects knowing anything about each other.
Syntax: connect(sender, SIGNAL(signal), receiver, SLOT(slot));
From docs:
-- Is approximately ten times slower than calling the receivers directly, with non-virtual function calls
-- It's much less overhead than any new or delete operation, for example. -- The same is true whenever you do a system call in a slot -- Or indirectly call more than ten functions.
-- Extra GUI feature with automatic connections
http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections
-- General info about Singals and Slots: http://doc.qt.io/qt-5/signalsandslots.html
Common Qt Architecture things
-- For every Qt class, there is a header file with the same name (and capitalization) as the class that contains the class's definition
-- QApplication manages application-wide resources. Qt application users can override the default style by using the -style command-line option.
-- Window is widget without parent. Qt is so flexible that any widget can be a window.
-- Q_OBJECT macro at the beginning of the class definition is necessary for all classes that define signals or slot. -- Q_OBJECT macro is special macro which will include special rules during expansion for moc, Qt's meta-object compiler.
-- In QT every new doesn't have a matching delete. Parent will delete children.
-- Starting from Qt 5 is possible to connect signal to lambda function
connect(ui->btnExit, &QPushButton::clicked, [this]()
{
this->close();
}
);
-- http://doc.qt.io/qt-5/qobject.html.
The signal must be a function declared as a signal in the header. The slot function can be any function that can be connected to the signal.
A function can be connected to a given signal if the signal has at least as many argument as the slot.
-- In the string literals for Widgets we can use ampersands ('&') to indicate shortcut keys.
-- The default tab order is the order in which the widgets were created. This can be changed using QWidget::setTabOrder().
Example:
#include <QObject>class Counter : public QObject{Q_OBJECT
public: Counter() { m_value = 0; } int value() const { return m_value; }public slots: void setValue(int value);signals: void valueChanged(int newValue);private: int m_value;};
Features: -- Two signals will be emitted for duplicate connections -- "CONFIG += no_keywords" tells Qt not to define the moc keywords signals, slots, and emit. In that case we should use:
Q_SIGNALS (or Q_SIGNAL), Q_SLOTS (or Q_SLOT), and Q_EMIT.
-- Signals are emitted with emit QT keyword.
Example of simple signal connection:
connect(targetText, SIGNAL(textChanged(const QString &)), this, SLOT(enableFindButton(const QString &)));
About Events.
Events are generated by the window system or by Qt itself in response to various occurrences. When we program with Qt, we seldom need to think about events, because Qt widgets emit signals when something significant occurs.
Events become useful when we write our own custom widgets or when we want to modify the behavior of existing Qt widgets.
Accept and ignore QEvent.
event->accept()
event->ignore()
event was processed
event can not be processed here in "this function". Try to send an event to my parent.
From doc:
"It is set by default, but don't rely on this as subclasses may choose to clear it in their constructor."
Memory ownership and dtor
QObject has children.
If your class is derived from QObject and it is a member of some other class then dtor for it can be potentially called from two places:
a) During dtor of the object of which this instance is member of (dtor C++ behavior)
b) During dtor of parent (QObject relation).
By the way during Layouting mechanism will automatically reparent the widgets.
Widgets in a layout are children of the widget on which the layout is installed.
What controls to use?
* Which one is more intuitive?
* Toolbar for quick action
* Don't create too complex dialog boxes
* Google Chrome doesn't have a menu bar, but it has one menu button (right corner)
* Use radio buttons for a shortlist, e.g. < 10 items, in other case use, drop-down lists
* One textBox with validation can be better choice than multi-stage-selection by buttons
* Group related items together. Separate unrelated items
* Use contrasting colors for clarity. A useful tool with color themes: Adobe Kuler https://color.adobe.com/
Example of good layout from [I]
Qt's Widgets Application uses a styling system called Qt Style Sheets, which is similar to the web technology's styling system
CSS (Cascading Style Sheet).
All you need to do is write the style description of the widget and Qt will render it accordingly.
The syntax of Qt Style Sheets is pretty much the same as CSS. Example:
QLineEdit { color: blue; background-color: black; }
(p.443, c-gui-programming-with-qt-4-2nd edition)
QImage - Optimised for I/O, direct pixel access, and manipulation
QPixmap - Optimised for display on the screen
QBitmap - Inherited from QPixmap for black/white images
QPicture - Paint device that records and replays QPainter commands
- Display (QLabel, QLCDNumber, QProgressBar, QTextBrowser)
- Button (QCheckBox, QRadioButton, QPushButton, QToolButton)
- Input (QLineEdit, QDateEdit, QTimeEdit, QSlider, QSpinBox, QDoubleSpinBox, QScrollBar, QComboBoxm QFontComboBox)
- Container (QGroupBox, QFrame)
- Item view (QTreeView, QTableView)
- Dialog (QMessageBox, QErrorMessage, QProgressDialog, QColorDialog, QFileDialog)
- Qt SQL. It's possible to retrieve data from a SQL database using Qt's SQL module.
- Qt Multimedia. The multimedia module in Qt is the module that handles a platform's multimedia capabilities: media playback, camera, and radio.
- Qt networking. This module and how it can help us to achieve server-client communication via the TCP or UDP connection protocols.
- Qt WebEngine. This module supports the Web. In the past Qt used WebKit to render web content on its user interface. However, the WebKit module has been completely deprecated since version 5.5 and replaced by a new module called WebEngine. The new WebEngine module is based on the Chromium framework built by Google.
#include <QApplication>#include <QLabel>int main(int argc, char *argv[]){ QApplication app(argc, argv); QLabel *label = new QLabel("Hello World!"); label->show(); return app.exec();}
#include <QtGui>#include <QHBoxLayout>#include <QLabel>#include <QSpinBox>#include <QSlider>#include <QPushButton>int main(int argc, char *argv[]){ QApplication app(argc, argv); QHBoxLayout *topRow = new QHBoxLayout; topRow->addWidget(new QLabel("value")); topRow->addWidget(new QSpinBox); topRow->addWidget(new QSlider(Qt::Horizontal)); QHBoxLayout *bottomRow = new QHBoxLayout; // Create layout to put widgets in place bottomRow->addWidget(new QPushButton("apply")); //bottomRow->addStretch(10); bottomRow->addStretch(10); bottomRow->addWidget(new QPushButton("close")); QVBoxLayout *vbox = new QVBoxLayout; //vbox->addLayout(topRow); vbox->addLayout(bottomRow); QWidget *main = new QWidget; main->setLayout(vbox); // Put layout in main window //main->setFixedSize(300, 100); //main->adjustSize(); //main->setMaximumSize(); main->show(); return app.exec();}
Widgets list
Qt Widgets C++ Classes | Qt Widgets 5.15.3
virtual void paintEvent(QPaintEvent *event)
http://doc.qt.io/qt-5/qabstractscrollarea.html
"For convenience, QAbstractScrollArea makes all viewport events available in the virtual viewportEvent() handler.
QWidget's specialized handlers are remapped to viewport events in the cases where this makes sense.
The remapped specialized handlers are: paintEvent(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), wheelEvent(), dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), dropEvent(), contextMenuEvent(), and resizeEvent()."
Ответ неизвестного человека: https://www.linux.org.ru/forum/development/12423388
Раскрою немного вашу мысль: все, что наследуется от QAbstractScrollArea, требует вызова painter-а на viewport(), а не на this,
потому что отрисовка на самом деле выполняется на viewport-е.
apt-get install qt5-default qttools5-dev-tools qtcreator qt4-demos qt4-doc qt4-doc-html qt5-doc qt5-doc-html qtbase5-examples qtbase5-doc-html
===================Extra libraries for qt in linux========================
apt-get install g++ build-essential
apt-get install "^libxcb.*"
apt-get install libx11-xcb-dev libglu1-mesa-dev libxrender-dev
===============================================================
1. Install Windows CDB debugger (e.g. https://www.microsoft.com/en-us/download/confirmation.aspx?id=8279)
2. Download and install Qt
3. Install if need Ninja and append the path to it into PATH
4. Install if need CMake and append the path to it into PATH
Tricks with Qt
1. Expanding switch statement
a. type switch(option)
b. select switch and press ALT+Enter
2. Auto Indentation
a. Select Text
b. Press Ctrl+I
3. Available QtCreator plugins
https://wiki.qt.io/Qt_Creator_Plug-in_Gallery
4. QtCreator shortcuts mentioned in the official documentation
https://wiki.qt.io/Qt_Creator_Keyboard_Shortcuts
About Layouting and Size:
Every widget that is placed on a form must be given an appropriate size and position. Qt provides several classes that layout widgets on a form - QHBoxLayout, QVBoxLayout, QGridLayout, and QStackedLayout. These classes are so convenient and easy to use that almost every Qt developer uses them, either directly in source code or through Qt Designer.
The margins around layout can be confgiured with QLayout::setContentsMargins() and QLayout::setSpacing().
Qt provides several size policies: