Niamita
12th October 2011, 09:33
I have a custom frame class which is like this-
button::button(QWidget *parent) :
QMainWindow(parent){
resized = false;
desktop = QApplication::desktop();
screenwidth = desktop->width(); // get width of screen
screentheight = desktop->height(); // get height of screen
this->setGeometry(0, 0, screenwidth, screentheight);
this->setWindowTitle("Home Profile");
void button::paintEvent(QPaintEvent *event ){
QPainter painter_menu_button(this);
QPen pen_menu_button(QColor(10, 10, 10, 120));
painter_menu_button.setPen(pen_menu_button);
painter_menu_button.setRenderHint(QPainter::Antial iasing);
painter_menu_button.setBrush(QColor(255, 255, 255));
/************************************ Home Button **************************************/
static const QPointF points_home[4] = {
QPointF(Home_Profile_Q1_X, Home_Profile_Q1_Y),
QPointF(Home_Profile_Q2_X, Home_Profile_Q2_Y),
QPointF(Home_Profile_Q3_X, Home_Profile_Q3_Y),
QPointF(Home_Profile_Q4_X, Home_Profile_Q4_Y),
};
painter_menu_button.drawPolygon(points_home, 4);
/************************************ Emergency Button **************************************/
static const QPointF points_emergency[4] = {
QPointF(Emergency_Help_Q1_X, Emergency_Help_Q1_Y),
QPointF(Emergency_Help_Q2_X, Emergency_Help_Q2_Y),
QPointF(Emergency_Help_Q3_X, Emergency_Help_Q3_Y),
QPointF(Emergency_Help_Q4_X, Emergency_Help_Q4_Y),
};
painter_menu_button.drawPolygon(points_emergency, 4);
/************************************ Light Button **************************************/
static const QPointF points_light[4] = {
QPointF(Light_Q1_X, Light_Q1_Y),
QPointF(Light_Q2_X, Light_Q2_Y),
QPointF(Light_Q3_X, Light_Q3_Y),
QPointF(Light_Q4_X, Light_Q4_Y),
};
painter_menu_button.drawPolygon(points_light, 4);
/************************************ Video Button **************************************/
static const QPointF points_video[4] = {
QPointF(Video_Voor_Q1_X, Video_Voor_Q1_Y),
QPointF(Video_Voor_Q2_X, Video_Voor_Q2_Y),
QPointF(Video_Voor_Q3_X, Video_Voor_Q3_Y),
QPointF(Video_Voor_Q4_X, Video_Voor_Q4_Y),
};
painter_menu_button.drawPolygon(points_video, 4);
/************************************ Curtains Button **************************************/
static const QPointF points_curtains[4] = {
QPointF(Curtains_Q1_X, Curtains_Q1_Y),
QPointF(Curtains_Q2_X, Curtains_Q2_Y),
QPointF(Curtains_Q3_X, Curtains_Q3_Y),
QPointF(Curtains_Q4_X, Curtains_Q4_Y),
};
painter_menu_button.drawPolygon(points_curtains, 4);
/************************************** Custom Button **************************************/
static const QPointF points_custom[4] = {
QPointF(Custom_Comfort_Q1_X, Custom_Comfort_Q1_Y),
QPointF(Custom_Comfort_Q2_X, Custom_Comfort_Q2_Y),
QPointF(Custom_Comfort_Q3_X, Custom_Comfort_Q3_Y),
QPointF(Custom_Comfort_Q4_X, Custom_Comfort_Q4_Y),
};
painter_menu_button.drawPolygon(points_custom, 4);
/************************************* Button Text Drawing ***********************************/
QPainter painter_text(this);
QPen pen_text(QColor(189, 127, 66, 255));
painter_text.setPen(pen_text);
if((screenwidth >= 800) && (screenwidth <= 1024)){
QFont font("Verdana", 11);
painter_text.setFont(font);
}
if((screenwidth > 1024) && (screenwidth <= 1366)) {
QFont font("Verdana", 14);
painter_text.setFont(font);
}
QRect button1_text_1stline = QRect(Text_Home_X, Text_Home_Y, screenwidth/13, screentheight/30);
painter_text.drawText( button1_text_1stline, Qt::AlignLeft, "Home");
QRect button1_text_2ndtline = QRect(Text_Profile_X, Text_Profile_Y, screenwidth/13, screentheight/30);
painter_text.drawText( button1_text_2ndtline, Qt::AlignLeft, "Profile");
QRect button2_text_1stline = QRect(Text_Emergency_X, Text_Emergency_Y, screenwidth/13, screentheight/30);
painter_text.drawText( button2_text_1stline, Qt::AlignLeft, "Emerency");
QRect button2_text_2ndline = QRect(Text_Help_X, Text_Help_Y, screenwidth/13, screentheight/30);
painter_text.drawText( button2_text_2ndline, Qt::AlignCenter, "Help");
QRect button3_text1stline = QRect(Text_Light_X, Text_Light_Y, screenwidth/13, screentheight/30);
painter_text.drawText( button3_text1stline, Qt::AlignCenter, "Lights");
QRect button4_text1stline = QRect(Text_Video_Door_X, Text_Video_Door_Y, screenwidth/12, screentheight/30);
painter_text.drawText( button4_text1stline, Qt::AlignCenter, "Video Door");
QRect button4_text2ndline = QRect(Text_Phone_X, Text_Phone_Y, screenwidth/13, screentheight/30);
painter_text.drawText( button4_text2ndline, Qt::AlignCenter, "Phone");
QRect button5_text1stline = QRect(Text_Curtains_X, Text_Curtains_Y, screenwidth/13, screentheight/30);
painter_text.drawText( button5_text1stline, Qt::AlignCenter, "Curtains");
QRect button6_text1stline = QRect(Text_Custom_X, Text_Custom_Y, screenwidth/13, screentheight/30);
painter_text.drawText( button6_text1stline, Qt::AlignLeft, "Custom");
QRect button6_text2ndline = QRect(Text_Comfort_X, Text_Comfort_Y, screenwidth/13, screentheight/30);
painter_text.drawText( button6_text2ndline, Qt::AlignLeft, "Comfort");
}
above is a frame have buttons drawn by paint.
Now my main class in which i use this frame in a layout
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)//,
//ui(new Ui::MainWindow)
{
//ui->setupUi(this);
QDesktopWidget *desktop = QApplication::desktop();
screenWidth = desktop->width(); // get width of screen
screenHeight = desktop->height(); // get height of screen
this->setGeometry(1,30,screenWidth,screenHeight);
button_on = new QPushButton(this);
button_on->setText("ON");
button_on->setMaximumSize(Button_1st_Width, Button_1st_Height);
//button_on->setGeometry(Button_On_X, (screenHeight/2) - screenHeight/20, Button_On_Width, Button_On_Height);
button_off = new QPushButton(this);
button_off->setText("OFF");
button_off->setMaximumSize(Button_1st_Width, Button_1st_Height);
//button_off->setGeometry(Button_Off_X, (screenHeight/2) - screenHeight/20, Button_Off_Width, Button_Off_Height);
button_1st = new QPushButton(this);
//button_1st->setGeometry(Button_1st_X, screenHeight/4 - (screenHeight/10), Button_1st_Width, Button_1st_Height);
button1 = 75;
button_1st->setMaximumSize(Button_1st_Width, Button_1st_Height);
button_1st->setText(QString::number(button1) + "%");
button_2nd = new QPushButton(this);
//button_2nd->setGeometry(Button_2nd_X, (screenHeight/4 - (screenHeight/10)) + screenHeight/8, Button_2nd_Width, Button_2nd_Height);
button2 = 50;
button_2nd->setMaximumSize(Button_1st_Width, Button_1st_Height);
button_2nd->setText(QString::number(button2) + "%");
button_3rd = new QPushButton(this);
//button_3rd->setGeometry(Button_3rd_X, (screenHeight/4 - (screenHeight/10)) + screenHeight/8 + screenHeight/8, Button_3rd_Width, Button_3rd_Height);
button3 = 25;
button_3rd->setText(QString::number(button3) + "%");
button_3rd->setMaximumSize(Button_1st_Width, Button_1st_Height);
button_up_arrow = new QPushButton(this);
button_up_arrow->setMaximumSize(Button_1st_Width, Button_1st_Height);
//button_up_arrow->setGeometry(Button_up_arrow_X, (screenHeight/4 - (screenHeight/10)) + screenHeight/15, Button_up_arrow_Width, Button_up_arrow_Height);
button_down_arrow = new QPushButton(this);
button_down_arrow->setMaximumSize(Button_1st_Width, Button_1st_Height);
//button_down_arrow->setGeometry(Button_down_arrow_X, (screenHeight/4 - (screenHeight/10)) + screenHeight/5, Button_down_arrow_Width, Button_down_arrow_Height);
label_light_name = new QLabel(this);
label_light_name->setText("Gym Light");
label_light_name->setMaximumSize(Button_1st_Width, Button_1st_Height);
//label_light_name->setGeometry(screenWidth/3 + screenWidth/12, screenHeight/50, Button_1st_Width, Button_1st_Height);
QFrame *frame = new QFrame(this);
this->setCentralWidget(frame);
button *btn = new button(this);
//var = btn->minimumSizeHint();
//qDebug()<<var;
QGridLayout *grid = new QGridLayout(this);
grid->setVerticalSpacing(20);
grid->setHorizontalSpacing(40);
grid->addWidget(btn, 0,0);
grid->addWidget(label_light_name, 0,2,1,4);
grid->addWidget(button_1st, 1,1);
grid->addWidget(button_2nd,2,1);
grid->addWidget(button_3rd,3,1);
grid->addWidget(button_up_arrow, 1,2,2,1);
grid->addWidget(button_down_arrow, 2,2,2,1);
grid->addWidget(button_on,4,0);
grid->addWidget(button_off,4,3);
// grid->setColumnStretch(0,60);
// grid->setColumnStretch(1,500);
frame->setLayout(grid);
}
Problem is that when i resizing the window all widget autofit to window but shape drawn over frame does not fit.
I have to autofit shapes also.
Please guide me.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.