In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the Qt development skills". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "what are the Qt development skills" together.
In the process of using QList, QStringList, QByteArray and other linked lists or arrays, if only values are needed instead of assignments, it is strongly recommended to use at() values instead of [] operators. In the official book C++ GUI Qt 4 Programming (Second Edition), there is a special emphasis. The original author of this textbook is said to have been written by the core personnel of Qt development, so it is still relatively authoritative. As for the comparison between the speed efficiency of using at() and using the [] operator, some netizens have also made such comparisons online. Qt uses implicit sharing for all containers and many other classes. Implicit sharing is a guarantee that Qt will never copy data it does not want to modify. To make implicit sharing work best, two new programming habits can be adopted. The first habit is to use the at() function instead of the [] operator for read-only access to a (very large) vector or list, because the container class of Qt cannot tell whether the [] operator will appear to the left or right of an assignment, assuming the worst case and forcing deep assignments, while the at() function is not allowed to appear to the left of an assignment.
If it is a dialog form, you need to be able to continue other code after exec. Please add a line of code before dialog form exec, otherwise it will block the form message.
QDialog dialog;dialog.setWindowModality(Qt::WindowModal);dialog.exec();
Safe deletion of Qt object classes, it is strongly recommended to use deleteLater rather than delete, because deleteLater will choose to release at the right time, while delete will release immediately, and it is likely to crash. If you want to delete the object collection in batches, you can use qDeleteAll, such as qDeleteAll(btns);
In QTableView control, if you need custom column buttons, check boxes, drop-down boxes and other modes to display, you can use custom delegation QItemDelegate to achieve, if you need to disable a column, then in the custom delegation overloaded createEditor function returns 0. The control corresponding to the custom delegate appears when entering the editing state. If you want to appear all the time, you need to overload the paint function to draw with drawPrimitive or drawControl.
QApplication::style() corresponding drawPrimitive, drawControl, drawItemText, drawItemPixmap and other methods are familiar with, combined with QStyleOption attribute, you can play various custom delegates, you can also directly use the painter in the paint function to draw various kinds of awesome tables, tree lists, drop-down boxes, etc., absolutely awesome. QApplication::style()->drawControl If the fourth parameter is not set, the control drawn will not apply the style sheet.
With coordinates in mind, everything is painter. It is strongly recommended to read, try and understand all the functions in the qpainter.h header file when learning custom control drawing. It contains all the built-in drawing interfaces of Qt. The corresponding parameters are tried again. You will find many new continents, which will greatly stimulate your interest in drawing. Just like the magic pen Ma Liang, you will ride the horse to travel the world of code drawing.
In the process of using setItemWidget or setCellWidget, sometimes you will find that the set control is not centered but the default left alignment, and will not automatically stretch the fill, for the pursuit of perfect programmers, this can not look good, there is an ultimate general way is to put this control into a widget layout, and then add the widget to the item, so that the perfect solution, and this can be combined with multiple controls to produce complex controls.
//Instantiate the progress bar control QProgressBar *progress = new QProgressBar;//add widget+ layout to achieve clever centering QWidget *widget = new QWidget;QHBoxLayout *layout = new QHBoxLayout;layout->setSpacing(0);layout->setMargin(0);layout->addWidget(progress);widget->setLayout(layout);ui->tableWidget->setCellWidget(0, 0, widget);
In many cases, it is necessary to be able to draw text clearly when the background color is known. At this time, it is necessary to calculate the corresponding text color.
//Automatically calculate the appropriate foreground color according to the background color double gray = (0.299 * color.red () + 0.587 * color.green () + 0.114 * color.blue ()) / 255;QColor textColor = gray > 0.5 ? Qt::black : Qt::white;
Disable column dragging for QTableView or QTableWidget.
#if (QT_VERSION tableView->horizontalHeader()->setResizeMode(0, QHeaderView::Fixed);#else ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);#endif
From Qt4 to Qt5, some class methods are obsolete or obsolete. If you want to enable Qt4 methods in Qt5, such as setMovable of QHeadVew, you can add a line to your pro or pri file: DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
Thank you for reading, the above is the content of "Qt development skills," after the study of this article, I believe that we have a deeper understanding of Qt development skills, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.