Thanks Marcel,
I forgot to creat an instance of MyWidget. I fixed that, and i also used layout to handle the position and size of my quit button.
But, my "quit" button (b_quit) isnt working. The window wont close when i press "Quit". I would like to know where is the problem.
Here is the fixed code:
#include <QApplication>
#include "browseimages.h"
#include <QPushButton>
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <Qlabel>
{
public:
};
MyWidget
::MyWidget(QWidget *parent
) {
connect(b_quit, SIGNAL(clicked()), qApp, SLOT(b_quit()));
b_search->setFixedHeight(40);
b_quit->setFixedHeight(40);
v_search->setAlignment(Qt::AlignCenter);
l_search_img
->setPixmap
(QPixmap("images/manual.png"));
v_search->addWidget(l_search_img);
v_search->addWidget(b_search);
h_quit->addStretch();
h_quit->addWidget(b_quit);
h_quit->addStretch();
layout_mid->addLayout(v_search);
layout_vert->addLayout(layout_mid);
layout_vert->addSpacing(30);
layout_vert->addLayout(h_search);
layout_vert->addLayout(h_quit);
layout_vert->addSpacing(30);
this->setLayout(layout_vert);
}
int main(int argc, char **argv)
{
MyWidget widget;
widget.show();
return app.exec();
}
#include <QApplication>
#include "browseimages.h"
#include <QPushButton>
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <Qlabel>
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
};
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
QPushButton *b_quit = new QPushButton(tr("Quit"));
QPushButton *b_search = new QPushButton(tr("Search"));
connect(b_quit, SIGNAL(clicked()), qApp, SLOT(b_quit()));
b_search->setFixedHeight(40);
b_quit->setFixedHeight(40);
QVBoxLayout *v_search = new QVBoxLayout;
v_search->setAlignment(Qt::AlignCenter);
QLabel *l_search_img = new QLabel();
l_search_img->setPixmap(QPixmap("images/manual.png"));
v_search->addWidget(l_search_img);
v_search->addWidget(b_search);
QHBoxLayout *h_quit = new QHBoxLayout;
h_quit->addStretch();
h_quit->addWidget(b_quit);
h_quit->addStretch();
QVBoxLayout *layout_vert = new QVBoxLayout;
QHBoxLayout *layout_mid = new QHBoxLayout;
layout_mid->addLayout(v_search);
layout_vert->addLayout(layout_mid);
layout_vert->addSpacing(30);
QHBoxLayout *h_search = new QHBoxLayout;
layout_vert->addLayout(h_search);
layout_vert->addLayout(h_quit);
layout_vert->addSpacing(30);
this->setLayout(layout_vert);
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Thanks in advance,
Bookmarks