Namespaces
Variants
Actions

Implementing QTreeView in QComboBox using Qt- Part 1

Jump to: navigation, search
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

Treecombo.JPG


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

This page was last modified on 11 October 2012, at 04:17.
231 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved