Summary of QT knowledge points (2)

1. If there is a resource in a library, you need to call Q_INIT_RESOURCE() with a parameter without the suffix of the .qrc file name to force the initialization of the resource system.

2. You can use qobject_cast() to dynamically convert the type of the QObject class

3. Custom types need to be registered with the Q_DECLARE_METATYPE() macro so that their values ​​can be saved in the QVariant object

4. QCoreApplication::sendEvent() (synchronous) and QCoreApplication::postEvent() (asynchronous queue) send the constructed event to the specified receiver.

5. When using the layout, there is no need to specify the parent when building the child controls, the layout will automatically specify the parent (using QWidget::setParent()), making them the child controls of the interface where the layout is installed

  • QWidget::sizeHint() returns the preferred size of the widget
  • QWidget::minimumSizeHint() returns the smallest size that the widget can have
  • QWidget::setSizePolicy() specifies the space required by the widget

6. QBoxLayout member functions:

//添加控件到布局,参数:控件 拉伸参数对齐方式
addWidget(QWidget *, int stretch = 0, Qt::Alignment alignment = 0)

//添加控件到布局,参数:控件 拉伸参数
addLayout(QLayout *layout, int stretch)
//设置控件的拉伸参数
setStretchFactor(QWidget *w, int stretch);
setStretchFactor(QLayout *l, int stretch); 

7. QGridLayout: grid layout
 

//这个单元将从row和column开始,扩展到rowSpan和columnSpan指定的倍数的行和列。如果rowSpan或//columnSpan的值为-1,则窗口部件将扩展到布局的底部或者右边边缘处。
void addWidget(QWidget *, int row, int column, int rowSpan, int columnSpan, Qt::Alignment = 0);
void addLayout(QLayout *, int row, int column, int rowSpan, int columnSpan, Qt::Alignment = 0)

//设置间距
setSpacing(int spacing) //同时设置水平及竖直间距
setHorizontalSpacing(int spacing)
setVerticalSpacing(int spacing) 

8. Form layout (QFormLayout) is suitable for combination with QLabel and QLineEdit

The QStackedLayout class provides a multi-page switching layout, and only one interface can be seen at a time. Same as QStackedWidget

9. The QSpacerItem class provides a blank area for the layout: QSpacerItem(int w, int h, QSizePolicy::Policy hData = QSizePolicy::Minimum, QSizePolicy::Policy vData = QSizePolicy::Minimum)

The layout class can use addSpaceItem to add a blank area

10. QTemporaryFile is used to safely create a unique temporary file, and the temporary file will be deleted with the destruction of the QTemporaryFile object.

11. The QCryptographicHash class provides methods for generating password hashes.

12. You can use qInstallMessageHandler() to output detailed logs

13. Use the environment variable QT_MESSAGE_PATTERN or qSetMessagePattern to change the output format of the printed message

 

Guess you like

Origin blog.csdn.net/Chiang2018/article/details/103189334