I amk new to qt. I tried to create a window with a widget. The widget contains a picture(a chess board). Now, If I tried to show the window it is showing a part of that picture. Here the code
#include<QApplication>
#include<QMainWindow>
#include<QWidget>
#include<QMenu>
#include<QMenuBar>
#include<QPainter>
#include<QFrame>
#include<QHBoxLayout>
#include<iostream>
using namespace std;
class MyWindow:public QMainWindow
{
public:
MyWindow();
};
class MyWidget:public QWidget
{
public:
MyWidget();
void paintEvent(QPaintEvent * event);
};
int main(int argc,char *argv[])
{
Q_INIT_RESOURCE(puzzle);
QApplication app(argc,argv);
MyWindow mainWindow;
mainWindow.show();
return app.exec();
}
MyWindow::MyWindow():QMainWindow()
{
setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed));
QMenu * fileMenu=menuBar()->addMenu(QObject::tr("Options"));
QAction * restartAction = fileMenu->addAction(tr("NewGame"));
QAction * exitAction = fileMenu->addAction(tr("Exit"));
exitAction->setShortcuts(QKeySequence::Quit);
QWidget * tempWidget=new MyWidget();
QFrame * newFrame=new QFrame();
QHBoxLayout * horizontal= new QHBoxLayout(newFrame);
horizontal->addWidget(tempWidget);
setCentralWidget(newFrame);
}
MyWidget::MyWidget():QWidget()
{
setMinimumSize(100,100);
setMaximumSize(1000,1000);
}
void MyWidget::paintEvent(QPaintEvent * event)
{
QPainter painter;
painter.begin(this);
painter.drawPixmap(QRect(0,0,500,600),QPixmap("Board").scaled(QSize(500,600),Qt::KeepAspectRatioByExpanding,Qt::SmoothTransformation));
painter.end();
}