Find icon in a dialog box

  • Hi,
    I have created the following dialog box for finding files. It works correctly as I can find files, but my problem is that I cannot see .png image file included in my directory.Could someone tell me what to change or what to add in my code?

    //////////////// window.cpp //////////
    @ #include <QtGui>

    #include "window.h"

    Window::Window(QWidget *parent)
    : QDialog(parent)

     browseButton = createButton(tr("&Browse..."), SLOT(browse()));

    openButton = createButton(tr("&Open"), SLOT(open_file()));

     directoryComboBox = createComboBox(QDir::currentPath());
     directoryLabel = new QLabel(tr("In directory:"));
     QHBoxLayout *buttonsLayout = new QHBoxLayout;


     QGridLayout *mainLayout = new QGridLayout;
     mainLayout->addWidget(directoryLabel, 2, 0);
     mainLayout->addWidget(directoryComboBox, 2, 1);
     mainLayout->addWidget(browseButton, 2, 2);
     mainLayout->addLayout(buttonsLayout, 5, 0, 1, 3);
     setWindowTitle(tr("Open Files"));
     resize(500, 200);


    void Window::open_file()
    /// an 8elw na anoiksw thn eikona me graphicsView
    QGraphicsScene * scene = new QGraphicsScene();


    void Window::browse()
    QString directory = QFileDialog::getExistingDirectory(this,
    tr("Open Files"), QDir::currentPath());
    if (!directory.isEmpty()) {
    directoryComboBox->setCurrentIndex(directoryComboBox->currentIndex() + 1);

    QPushButton *Window::createButton(const QString &text, const char *member)
    QPushButton *button = new QPushButton(text);
    connect(button, SIGNAL(clicked()), this, member);
    return button;

    QComboBox *Window::createComboBox(const QString &text)
    QComboBox *comboBox = new QComboBox;
    comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    return comboBox;

    ////////////// window.h ////////////////
    @#ifndef WINDOW_H
    #define WINDOW_H

    #include <QDialog>

    class QComboBox;
    class QDir;
    class QLabel;
    class QPushButton;

    class Window : public QDialog

    Window(QWidget *parent = 0);

    private slots:
    void browse();
    void open_file();


     QPushButton *createButton(const QString &text, const char *member);
     QComboBox *createComboBox(const QString &text = QString());
     QComboBox *directoryComboBox; 
     QLabel *directoryLabel;
     QPushButton *browseButton;

    QPushButton *openButton;



    //////////// main.cpp ////////////
    @#include <QApplication>

    #include "window.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);
    Window window;;
    return app.exec();

  • I think I have found it. I should have typed:
    @ void Window::browse()

      QString directory = QFileDialog::getOpenFileName( this , tr("Open File") ,
    QDir::currentPath() , tr("Images (*.png *.jpeg *.jpg *.bmp);; bmp (*.bmp);;jpg (*.jpeg *.jpg);;png (*.png)"));
     if (!directory.isEmpty()) {
         directoryComboBox->setCurrentIndex(directoryComboBox->currentIndex() + 1);


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.