Implementing QTreeView in QComboBox using Qt- Part 1
Article Metadata
Tested with
Devices(s): Symbian emulator
Compatibility
Platform(s): Qt
Article
Keywords: QComboBox,QTreeView,QFileSystemModel
Created: mind_freak
(12 Jul 2009)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Introduction
Here is the code snippet for the treeview implemented in combobox.In this their is file model object defined that has been set in the combobox(ui->comboBox->setModel(fsmodel);).we can navigate to the different directories by just opening the combox and selecting item.
Source Code
QFileSystemModel *fsmodel = new QFileSystemModel(this);
fsmodel->setRootPath("/");
setStyleSheet("* { background-color:rgb(90,20,60);color:rgb(255,255,255); padding: 7px}}");
QTreeView *tv = new QTreeView(ui->comboBox);
ui->comboBox->setStyleSheet("* { background-color:rgb(225,225,225);color:rgb(255,255,255); padding: 7px}}");
ui->comboBox->setView(tv);
ui->comboBox->setModel(fsmodel);
Screenshot
Problem
Given code snippet works fully,but their is a problem regarding the popup of the comboBox.As we click to expand the tree the comboBox popup closes,so we are not able to select the preferred item form the treeView at a time,number of clicks are to be made to select the preferred item.
Solution
For the solution of upper given problem visit:Implementing QTreeView in QComboBox using Qt- Part 2


article Provides a default model/view implementation of a tree view. It’s a good thing when we want to create an application which contain of all data storage view. In many application like file manager , Bluetooth file transfer this view is needed. Article named with “Implementing_QTreeView_in_QComboBox-II” is also the 70% same thing.
[--fasttrack 03:22, 16 September 2009 (UTC)]