Unable/not trained enough to get the expected look and feel. Any help/constructive suggestion appreciated.
!http://s12.postimg.org/n80v2twj1/cute.jpg(This is the way my widget looks like )!
So, the code reveals a QListView "linked" to a QStandardItemModel and other pretty useless lines of code.
@ model = new QStandardItemModel(this);
audioTypes = new QStandardItem(QIcon(":/gui/icons/audio-icon.png"),"Audio");
videoTypes = new QStandardItem(QIcon(":/gui/icons/video-icon.png"),"Video");
filesView->setModel(model);//filesView is the QTreeListView
btnLayout = new QHBoxLayout;
QString cancelText("revert changes");
QString acceptText("apply changes");
cancelBtn = new MToolButton(cancelIcon,cancelText);
acceptBtn = new MToolButton(acceptIcon,acceptText);
QStringList aExts = QString(".mp3,.ogg,.arm,.flac,.wma").split(",");
QStringList vExts = QString(".mkv,.avi,.mpeg4,.wmv").split(",");
QStandardItem *itm = new QStandardItem(aExt);
QStandardItem *itm = new QStandardItem(vExt);
Please forgive me for providing all the relevant code as a bulk(I tried to make the thread as light as possible). Also I know there are hard-coded lines and the code would need refactoring, but first I need to understand how to achieve what I need:
every item or sub-item must be non-editable and checkable.
parent items's(labeled with Audio and Video) check state must be related to the check state of their children. (I'm looking for a behaviour similar with the multi-selection of the gmail's inbox. I hope that's a relevant example of the functionality I need).
I'm new to Qt; my purpose is to try make some almost trivial gui applications for the sake of practicing while I'm reading/learning from recognized qt books.
This is a listview, not a treeview? Any reasons for that?
To make items non-editble, don't try to force that behavior by fiddling with the items, work with the view instead:
If you want to force a special setting for every item in the view, you could subclass QStandardItem, only reimplementing the constructor for now. About five lines of code and you wouldn't have to worry about "setCheckable" anymore.
As for the second point: There might be a signal emitted when an item is checked, that could be connected to some slot. If there is no such signal, you could tell your reimplemented QStandardItem to force its own checkstate upon its children. Using a tristate checkbox for the parent, the behavior could be reversed, too.
I hope this helps. If you need any more detail, first take a look into the Qt documentation, then feel free to ask again. :)
Thank you so much!
Everything you said definitely makes sense, nice explanation. I'll try to use your suggestions. Of course, I'll post the actual source files with appropriate comments for critique purposes and for other newbies redirected from search engines.
Given my current limited understanding of Qt, I had to give up for now. Audio and Video will no longer have checkboxes so there's no need for tri-state checkboxex now.
the code snippet I've previously posted belongs to this little app I've done:
I know next to nothing when it comes to software engineering and though I understand basic oop concepts and what's the purpose of MVC, I'm aware that I'm not familiar of basic best practices.
Please take a look and tell me what do you think and maybe make some concrete suggestions. I want to learn real life software engineering practices 'on the fly', while I'm hitting the books.
- I plan to fully comment the code tomorrow.
- The app may seem a little trivial, but I've found that many of my friends have the same problem. Many of them don't even now what shell is so it may help somebody.
- I plan to add some features, like a checkable option to remove dirs that are empty after the execution.
It's a open repository, so anyone feel free to find bugs/bad practices and/or provide better code.