Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Cửa sổ chính đòi hỏi phải có tên đối tượng để lưu các cửa sổ thuộc tính. Chúng tôi sẽ thảo luận về chủ đề này vào cuối Mục 4,8. Nếu tên là mất tích, Qt than phiền thời gian chạy trên đầu ra tiêu chuẩn. Thật không may, nó không phải là có thể thiết lập các thuộc tính windowTitle của QDockWidget trong thiết kế | 4 Developing a GDI Application Based on a Main Window Qt RightDockWidgetArea templateDocker- setObjectName TemplateDocker templateDocker- setWindowTitle tr Templates addDockWidget Qt LeftDockWidgetArea templateDocker QListView view new QListView templateDocker- setWidget view new TemplateHandler view textEdit this The main window requires the object name to save the window properties. We will discuss this topic at the end of Section 4.8. If the name is missing Qt complains at runtime on the standard output. Unfortunately it is not possible to set the windowTitle attribute of QDockWidget in the Designer which is why it is important that this must be done separately in the constructor. windowTitle labels the window and also gives a name to the toggle action that is generated by tog-gleViewAction . In the final step we breathe life into the widget by filling it with a list view. We will later find the templates in this view. The TemplateHandler class now instantiated is responsible for filling the list and for inserting templates at the current cursor position in the editor window cuteedit2 templatehandler.cpp TemplateHandler TemplateHandler QListView view QTextEdit textEdit QObject parent QObject parent mTextEdit textEdit mModel new QStringListModel this QStringList templates templates html html body body mModel- setStringList templates view- setModel mModel connect view SIGNAL clicked const QModelIndex SLOT insertText const QModelIndex In Qt 4 list views work on the basis of the model view principle introduced in Chapter 8 A model is responsible for obtaining data while the view displays the data. In the case of our templates one model is enough which takes data directly from a QStringList. As before these are fed with several templates in this case for HTML.16. We pass the list created in this way to the model via setStringList and turn this into the reference model for our view the list view. The list view is now filled and 16 Ina proper application the templates