PDA

View Full Version : How to make Search Dialog as it is used by MAC O.S



merry
11th June 2008, 07:04
Hi all

Working on MAC OS using Qt4.2 , I want to make a Search Dialog using Qt as it is used by the MAC O.S.

I dont have any idea from where should I start.

If anybody is having any idea abt dis then pls provide me some hints.

AD
11th June 2008, 07:22
Working on MAC OS using Qt4.2 , I want to make a Search Dialog using Qt as it is used by the MAC O.S.
I dont have any idea from where should I start.

Hi. What is problems? :)


#ifndef FINDDIALOG_H_055
#define FINDDIALOG_H_055

#include <QDialog>

class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;

class FindDialog: public QDialog
{
Q_OBJECT;

public:
FindDialog(QWidget* parent=0);

signals:
void findNext(const QString& str, Qt::CaseSensitivity cs);
void findPrev(const QString& str, Qt::CaseSensitivity cs);

private slots:
void findClicked();
void enableFindButton(const QString& text);

private:
QLabel* label;
QLineEdit* lineEdit;
QCheckBox* caseCheckBox;
QCheckBox* backwardCheckBox;
QPushButton* findButton;
QPushButton* closeButton;
};

#endif // FINDDIALOG_H_055



#include <QtGui>

#include "Finddialog.h"

FindDialog::FindDialog(QWidget* parent)
: QDialog(parent)
{
label = new QLabel(tr("Find &what:"));
lineEdit = new QLineEdit;
label -> setBuddy(lineEdit);

caseCheckBox = new QCheckBox(tr("Match &case"));
backwardCheckBox = new QCheckBox(tr("Search bacward"));

findButton = new QPushButton(tr("&Find"));
findButton -> setDefault(true);
findButton -> setEnabled(false);

closeButton = new QPushButton(tr("Close"));

connect(lineEdit, SIGNAL(textChanged(const QString&)),
this, SLOT(enableFindButton(const QString&)));
connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));

QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout -> addWidget(label);
topLeftLayout -> addWidget(lineEdit);

QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout -> addLayout(topLeftLayout);
leftLayout -> addWidget(caseCheckBox);
leftLayout -> addWidget(backwardCheckBox);

QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout -> addWidget(findButton);
rightLayout -> addWidget(closeButton);
rightLayout -> addStretch();

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout -> addLayout(leftLayout);
mainLayout -> addLayout(rightLayout);
setLayout(mainLayout);

setWindowTitle(tr("Find"));
setFixedHeight(sizeHint().height());
}

void FindDialog::findClicked()
{
QString text = lineEdit -> text();
Qt::CaseSensitivity cs = caseCheckBox -> isChecked() ? Qt::CaseSensitive
: Qt::CaseInsensitive;
if(backwardCheckBox -> isChecked())
emit findPrev(text, cs);
else
emit findNext(text, cs);
}

void FindDialog::enableFindButton(const QString& text)
{
findButton -> setEnabled(!text.isEmpty());
}




#include <QApplication>

#include "Finddialog.h"

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
FindDialog* dialog = new FindDialog;
dialog -> show();
return app.exec();
}

Compile by MinGW!

merry
11th June 2008, 07:50
Thanx 4 replying, But I dont want to make it as a separate application, I want to make as it is used by the MAC , that is search used in macintosh style.

AD
11th June 2008, 07:58
Thanx 4 replying, But I dont want to make it as a separate application, I want to make as it is used by the MAC , that is search used in macintosh style.
class FindDialog is used for your aim! You may this class in your aplications! I don't understand you! Why this class isn't use in your application?

merry
11th June 2008, 08:15
Actually i dont want to use it as a separate dialog in my application, I just want that when I enter text in the text box and presse enter key,then It displays all the result related to the text in the tree widget.

Pls preview the attachment, I want same for my application, like same box in which text to be find is written with same icon on the left and same close button on the right of the box in which text to be find is written.

merry
24th June 2008, 09:46
Can anybody know how to make NSSearchField using Qt4.3