#include <QApplication>#include <QMainWindow>#include "basicmenu.h"Basicmenu *chiOfBasicMenu;int main(int argc, char *argv[]){ QApplication app(argc, argv); QMainWindow *window = new QMainWindow; window -> setWindowTitle("Main Window"); window -> setGeometry ( 0, 0, 800, 480); chiOfBasicMenu = new Basicmenu(window); chiOfBasicMenu -> setGeometry (0, 0, 800, 480); window->show(); return app.exec();}
#ifndef BASICMENU_H#define BASICMENU_H#include <QGroupBox>#include "cell.h"class Basicmenu : public QWidget{public: Basicmenu (QWidget *parent = 0); void Highlightofrow(int numberOfRow); void KeyPressEvent(QKeyEvent *event); QGroupBox *borderOfMainMenu; Cell *cellOfArray[5][4]; };#endif
#include <QKeyEvent>#include "basicmenu.h"Basicmenu::Basicmenu(QWidget *parent) :QWidget(parent){ borderOfMainMenu = new QGroupBox(this); borderOfMainMenu -> setGeometry ( 0, 0, 800, 480); borderOfMainMenu -> setStyleSheet("background-color: #0821FF;"); for (int i=0; i<5; i++) { for (int j=0; j<4; j++) { cellOfArray[i][j] = new Cell(borderOfMainMenu); cellOfArray[i][j] -> setGeometry( (40*(j+1)+150*j), (30*(i+1)+60*i), 150, 60); } }}void Basicmenu::Highlightofrow(int numberOfRow){ for (int i=0; i<5; i++) cellOfArray[i][numberOfRow] -> borderOfCell -> setFrameStyle(QFrame::WinPanel | QFrame::Sunken);}void Basicmenu::KeyPressEvent(QKeyEvent *event){ event->accept(); switch (event->key()) { case 0x41: Highlightofrow(1); break; case 0x42: Highlightofrow(2); break; }}
#ifndef CELL_H#define CELL_H#include <QFrame>#include <QLabel>#include <QCheckBox>#include <QVBoxLayout>class Cell : public QWidget{public: Cell(QWidget *parent = 0); QFrame *borderOfCell; QLabel *nameOfCell; QCheckBox *visibilityOfCell; QVBoxLayout *placingInCell;};#endif
#include "cell.h"Cell::Cell(QWidget *parent) :QWidget(parent){ borderOfCell = new QFrame(this); borderOfCell -> setFrameStyle(QFrame::WinPanel | QFrame::Raised); borderOfCell -> setStyleSheet("color: #F4FF23;" "background-color: #4356FF;"); placingInCell = new QVBoxLayout; nameOfCell = new QLabel(borderOfCell); visibilityOfCell = new QCheckBox(borderOfCell); placingInCell -> addWidget(nameOfCell, 0, Qt::AlignCenter); placingInCell -> addWidget(visibilityOfCell, 0, Qt::AlignCenter); borderOfCell ->setLayout(placingInCell); borderOfCell-> setGeometry (0, 0, 150, 60);}
#include <QApplication>#include "mainwindow.h"int main(int argc, char *argv[]){ QApplication app(argc, argv); MainWindow *window = new MainWindow; window->show(); return app.exec();}
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include "basicmenu.h"class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); Basicmenu *chiOfBasicMenu;signals:protected: virtual void keyPressEvent(QKeyEvent *event);public slots:};#endif // MAINWINDOW_H
#include "mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ setWindowTitle("Main Window"); setGeometry ( 20, 20, 800, 480); chiOfBasicMenu = new Basicmenu(this); chiOfBasicMenu -> setGeometry (0, 0, 800, 480);}void MainWindow::keyPressEvent(QKeyEvent *event){ qDebug() << 1; switch (event->key()) { case Qt::Key_A: chiOfBasicMenu->Highlightofrow(1); break; case Qt::Key_B: chiOfBasicMenu->Highlightofrow(2); break; } QMainWindow::keyPressEvent(event);}
#ifndef BASICMENU_H#define BASICMENU_H#include "cell.h"class Basicmenu : public QWidget{ Q_OBJECTpublic: Basicmenu (QWidget *parent = 0); void Highlightofrow(int numberOfRow); virtual void KeyPressEvent(QKeyEvent *event); QGroupBox *borderOfMainMenu; Cell *cellOfArray[5][4];public slots:};#endif
#include "basicmenu.h"Basicmenu::Basicmenu(QWidget *parent) :QWidget(parent){ borderOfMainMenu = new QGroupBox(this); borderOfMainMenu -> setGeometry ( 0, 0, 800, 480); borderOfMainMenu -> setStyleSheet("background-color: #0821FF;"); for (int i=0; i<5; i++) { for (int j=0; j<4; j++) { cellOfArray[i][j] = new Cell(borderOfMainMenu); cellOfArray[i][j] -> setGeometry( (40*(j+1)+150*j), (30*(i+1)+60*i), 150, 60); } }}void Basicmenu::Highlightofrow(int numberOfRow){ for (int i=0; i<5; i++) cellOfArray[i][numberOfRow] -> borderOfCell -> setFrameStyle(QFrame::WinPanel | QFrame::Sunken);}void Basicmenu::KeyPressEvent(QKeyEvent *event){ qDebug() << 2; QWidget::keyPressEvent(event);}
#ifndef CELL_H#define CELL_H#include <QtCore>#include <QtGui>class Cell : public QWidget{public: Cell(QWidget *parent = 0); QFrame *borderOfCell; QLabel *nameOfCell; QCheckBox *visibilityOfCell; QVBoxLayout *placingInCell; virtual void keyPressEvent(QKeyEvent *event);};#endif
#include "cell.h"Cell::Cell(QWidget *parent) :QWidget(parent){ borderOfCell = new QFrame(this); borderOfCell -> setFrameStyle(QFrame::WinPanel | QFrame::Raised); borderOfCell -> setStyleSheet("color: #F4FF23;" "background-color: #4356FF;"); placingInCell = new QVBoxLayout; nameOfCell = new QLabel(borderOfCell); visibilityOfCell = new QCheckBox(borderOfCell); placingInCell -> addWidget(nameOfCell, 0, Qt::AlignCenter); placingInCell -> addWidget(visibilityOfCell, 0, Qt::AlignCenter); borderOfCell ->setLayout(placingInCell); borderOfCell-> setGeometry (0, 0, 150, 60);}void Cell::keyPressEvent(QKeyEvent *event){ qDebug() << 3; QWidget::keyPressEvent(event);}
class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); /*!!!*/Basicmenu *chiOfBasicMenu;
void MainWindow::keyPressEvent(QKeyEvent *event){ qDebug() << 1; switch (event->key()) { case Qt::Key_A: chiOfBasicMenu->Highlightofrow(1); break; case Qt::Key_B: chiOfBasicMenu->Highlightofrow(2); break; } QMainWindow::keyPressEvent(event);}