• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

README.mdH A D27-Jan-20213 KiB6351

filterabletreeview.cppH A D27-Jan-202110.6 KiB254153

filterabletreeview.hH A D27-Jan-20213 KiB7139

filterableview.cppH A D27-Jan-20211.4 KiB4213

filterableview.hH A D27-Jan-20211.3 KiB4016

searchbox.cppH A D27-Jan-20211.9 KiB6933

searchbox.hH A D27-Jan-20211.1 KiB4217

README.md

1Widgets
2=======
3
4The files in this directory define drop-in replacements for Qt's built-in
5widgets. These can be [used in QtCreator's Design mode][promoting-widgets]
6(i.e. in `.ui` files) or in ordinary `.h` and `.cpp` source files.
7
8[promoting-widgets]: http://doc.qt.io/qt-5/designer-using-custom-widgets.html#promoting-widgets
9
10## When to use
11
12Consider using or adapting these widgets if you can rather than creating your
13own. Doing this has the following benefits:
14
15- Saves time and effort
16- Easier to maintain
17- Ensures consistency in design
18- Reduces MuseScore's size and memory footprint
19- Benefit from extra features that you may not know how to implement yourself
20  (e.g. accessibility).
21
22If none of the existing widgets suit your particular need then consider
23creating your own and adding it to this directory. You can use one of the
24existing ones as a template, and even inherit from it if appropriate. Try to
25give the functions and classes names that are as generic as possible. Make
26sure you add comments where appropriate to help other people understand how
27to use the widgets, and to provide any details about the implementation that
28are not immediately obvious from the code.
29
30## Example
31
32`searchbox.h` defines SearchBox, a drop-in replacement for a QLineEdit, and
33`filterabletreeview.h` defines FilterableTreeView, which is a drop-in
34replacement for a QTreeView. When used together, these classes allow you to
35create a tree view to display hierarchical lists of items (e.g. books grouped
36by genre) and use the line edit to search in the view.
37
38You can use SearchBox and FilterableTreeView inside any of MuseScore's `.ui`
39files like this:
40
411. Open the UI file (e.g. `startcenter.ui`) in Qt Creator's Design mode.
422. Drag an instance of each of the base classes (QLineEdit and QTreeView) onto
43  the canvas (or find an existing instance).
443. Right-click the QLineEdit, choose "Promote to...", and enter the following:
45    - Promoted class name: `Ms::SearchBox` (`Ms` is the namespace)
46    - Header file: `widgets/searchbox.h`
474. Now do the same for the QTreeView:
48    - Promoted class name: `Ms::FilterableTreeView`
49    - Header file: `widgets/filterabletreeview.h`
505. Find the widgets' object names in the properties panel on the right.
51    - These are the names you will use to refer to the widgets in the code.
52    - Defaults are `treeView` and `lineEdit`. You might want to change them to
53      something more easily identifiable (e.g. `bookTree` and `bookSearch`).
54
55For many widgets that is all you need to do, but some will require additional
56setting-up to be done in the UI file's corresponding code files (in this case
57`startcenter.h` and `startcenter.cpp`). Look in those files for the line
58`setupUi(this);` and do whatever you have to do immediately after that line.
59The widget's source files (i.e. `searchbox.h`, `searchbox.cpp`, etc.) should
60tell you what you need to do. In this case, you just need to call the
61SearchBox's `setFilterableView(*view)` function with a pointer to the view
62that you want to search (i.e. `bookSearch->setFilterableView(bookTree);`).
63