I have written the following program using QWidget
and placed some pushbuttons and labels in layout and added those in another layout, but nothing is getting displayed except some default window.
Must i have QMainwindow always as a base widget?
please help.
apphub.cpp
----------------
#include "apphub.h"
#include<QDebug>
{
qDebug() << "AppHub";
Mainwidget->setLayout(MainLayout);
//Mainwidget->setPalette(QPalette(QColor(255,0,0,255)));
//Mainwidget->setAutoFillBackground(true);
Mainwidget->setMinimumSize(500,500);
for(int r=0;r<1;r++) {
for(int c=0;c<2;c++) {
App = new AppRsrc;
MainLayout->addWidget(App,r,c,10,2,Qt::AlignTop);
}
}
//Mainwidget->show();
// showing the window seperately , but without this also it should show
}
AppHub::~AppHub()
{
}
AppRsrc:: AppRsrc()
{
qDebug() << "AppRsrc";
AppWidget->resize(98,97);
AppWidget
->setPalette
(QColor(255,
0,
0,
255));
AppWidget->setAutoFillBackground(true);
QPixmap pixmap
(":/appimages/orca.png");
AppButton->setFixedSize(100,100);
AppButton->setIcon(AppIcon);
AppNameLbl->setFixedSize(83,20);
AppLayout->addWidget(AppButton);
AppLayout->addWidget(AppNameLbl);
AppWidget->setLayout(AppLayout);
}
AppRsrc:: ~AppRsrc()
{
}
#include "apphub.h"
#include<QDebug>
AppHub::AppHub(QWidget *parent) : QWidget(parent)
{
qDebug() << "AppHub";
Mainwidget = new QWidget;
MainLayout = new QGridLayout;
Mainwidget->setLayout(MainLayout);
//Mainwidget->setPalette(QPalette(QColor(255,0,0,255)));
//Mainwidget->setAutoFillBackground(true);
Mainwidget->setMinimumSize(500,500);
for(int r=0;r<1;r++) {
for(int c=0;c<2;c++) {
App = new AppRsrc;
MainLayout->addWidget(App,r,c,10,2,Qt::AlignTop);
}
}
//Mainwidget->show();
// showing the window seperately , but without this also it should show
}
AppHub::~AppHub()
{
}
AppRsrc:: AppRsrc()
{
qDebug() << "AppRsrc";
AppWidget = new QWidget ;
AppButton = new QPushButton;
AppLayout = new QVBoxLayout;
AppNameLbl = new QLabel;
AppWidget->resize(98,97);
AppWidget->setPalette(QColor(255,0,0,255));
AppWidget->setAutoFillBackground(true);
QPixmap pixmap(":/appimages/orca.png");
QIcon AppIcon(pixmap);
AppButton->setFixedSize(100,100);
AppButton->setIcon(AppIcon);
AppNameLbl->setFixedSize(83,20);
AppLayout->addWidget(AppButton);
AppLayout->addWidget(AppNameLbl);
AppWidget->setLayout(AppLayout);
}
AppRsrc:: ~AppRsrc()
{
}
To copy to clipboard, switch view to plain text mode
apphub.h
----------------
#ifndef APPHUB_H
#define APPHUB_H
#include <QWidget>
#include <QPushButton>
#include <QGridLayout>
#include <QLabel>
#include "app_rsrc.h"
class AppRsrc;
{
Q_OBJECT
public:
~AppHub();
private:
AppRsrc *App;
};
#endif // APPHUB_H
#ifndef APPHUB_H
#define APPHUB_H
#include <QWidget>
#include <QPushButton>
#include <QGridLayout>
#include <QLabel>
#include "app_rsrc.h"
class AppRsrc;
class AppHub : public QWidget
{
Q_OBJECT
public:
AppHub(QWidget *parent = 0);
~AppHub();
private:
QWidget *Mainwidget;
AppRsrc *App;
QGridLayout *MainLayout;
};
#endif // APPHUB_H
To copy to clipboard, switch view to plain text mode
app_rsrc.h
----------------
#ifndef APP_RSRC_H
#define APP_RSRC_H
#include<QPushButton>
#include<QLabel>
#include<QGridLayout>
#include<QIcon>
#include<QWidget>
{
private:
public:
AppRsrc();
~AppRsrc();
};
#endif // APP_RSRC_H
app_rsrc.h
----------------
#ifndef APP_RSRC_H
#define APP_RSRC_H
#include<QPushButton>
#include<QLabel>
#include<QGridLayout>
#include<QIcon>
#include<QWidget>
class AppRsrc : public QWidget
{
private:
QWidget *AppWidget;
QPushButton *AppButton;
QVBoxLayout *AppLayout;
QLabel *AppNameLbl;
public:
AppRsrc();
~AppRsrc();
};
#endif // APP_RSRC_H
To copy to clipboard, switch view to plain text mode
main.cpp
----------------
#include "apphub.h"
#include <QApplication>
#include<QMainWindow>
int main(int argc, char *argv[])
{
AppHub w;
w.show();
return a.exec();
}
#include "apphub.h"
#include <QApplication>
#include<QMainWindow>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AppHub w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks