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; buttonsLayout->addStretch();
buttonsLayout->addWidget(openButton);
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); setLayout(mainLayout); setWindowTitle(tr("Open Files")); resize(500, 200);
}
void Window::open_file()
{
/// an 8elw na anoiksw thn eikona me graphicsView
QGraphicsScene * scene = new QGraphicsScene();
scene->addPixmap(QPixmap(QDir::currentPath()));
//graphicsView->setScene(scene);}
void Window::browse()
{
QString directory = QFileDialog::getExistingDirectory(this,
tr("Open Files"), QDir::currentPath());
if (!directory.isEmpty()) {
directoryComboBox->addItem(directory);
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->setEditable(true);
comboBox->addItem(text);
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
{
Q_OBJECTpublic:
Window(QWidget *parent = 0);private slots:
void browse();
void open_file();private:
QPushButton *createButton(const QString &text, const char *member); QComboBox *createComboBox(const QString &text = QString()); QComboBox *directoryComboBox; QLabel *directoryLabel; QPushButton *browseButton;
QPushButton *openButton;
};
#endif@
//////////// main.cpp ////////////
@#include <QApplication>#include "window.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window window;
window.show();
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->addItem(directory); directoryComboBox->setCurrentIndex(directoryComboBox->currentIndex() + 1); }
}@