Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Find icon in a dialog box
Forum Updated to NodeBB v4.3 + New Features

Find icon in a dialog box

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jk_mk
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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();
    }@

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jk_mk
      wrote on last edited by
      #2

      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);
       }
      

      }@

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved