View Full Version : Customize the window in windows ?
iNewLegend
2nd May 2011, 14:34
Hello im good C++ developer , but i never used qt im total new in it, i wonder how to make the next setps by using codes not UI , in my image i selected the things i want done in red color , i used
w.setWindowFlags(Qt::FramelessWindowHint);
to hide windows one
cloud someone post me a code witch i can use QPushButton to make Close, and Mimimize buttons?
http://i56.tinypic.com/dqrfyd.jpg
thanks in advance
-----------------------------------------------------------
my next code :
int main(int argc, char *argv[])
{
QApplication App(argc, argv);
QWidget MainWnd;
QVBoxLayout Layout;
QPushButton CloseBt;
QPushButton MimimizeBt;
// ----
CloseBt.setText("X");
// ----
MimimizeBt.setText("_");
// ----
Layout.addWidget(& CloseBt, 0, Qt::AlignRight | Qt::AlignTop);
Layout.addWidget(& MimimizeBt, 2, Qt::AlignRight | Qt::AlignTop);
// ----
MainWnd.setLayout(& Layout);
MainWnd.setWindowFlags(Qt::FramelessWindowHint);
MainWnd.resize(800, 600);
MainWnd.show();
// ----
return App.exec();
}
does it:
http://i51.tinypic.com/2vv8k00.jpg
Zlatomir
2nd May 2011, 15:05
To reply strict to your question you can add this in your code:
QObject::connect(&MimimizeBt, SIGNAL(clicked()), &MainWnd, SLOT(showMinimized()));
QObject::connect(&CloseBt, SIGNAL(clicked()), &MainWnd, SLOT(close()));
And now a suggestion: use the heap for the child widgets (widgets that have a parent or will be "parented" by other widgets) - basically everything else then MainWnd.
***//else you can have some double-delete crash when close the application.
LE: you can read more about signals and slots here (http://doc.qt.nokia.com/4.7/signalsandslots.html)
***And a correction - on a second thought: the double-delete is not the cause of the crash - but the order of the delete the meta-object will call delete for a stack allocated object causing an error ;) (only if the parent is deleted before the child)
iNewLegend
2nd May 2011, 15:13
thanks bro , but main problem is the gui , i mean i dont know how to make it align normaly with size and be like this order , first mimmize box , then close box , extaly what i showed in the first image
Zlatomir
2nd May 2011, 15:16
Use a QHBoxLayout instead QVBoxLayout and add Minimize button first then Close.
iNewLegend
2nd May 2011, 15:18
Use a QHBoxLayout instead QVBoxLayout and add Minimize button first then Close.
thanks bro but they dont near ...
the close in center and mimimize in left
Zlatomir
2nd May 2011, 15:26
I don't understand your problem, do you want the buttons to be smaller?
Or the order is not right?
Have you reversed this lines, like:
QHBoxLayout Layout;
//...
Layout.addWidget(& MimimizeBt, 2, Qt::AlignRight | Qt::AlignTop);
Layout.addWidget(& CloseBt, 0, Qt::AlignRight | Qt::AlignTop);
Or you can attach another print-screen so that we will see what is going on.
iNewLegend
2nd May 2011, 15:31
I don't understand your problem, do you want the buttons to be smaller?
Or the order is not right?
Have you reversed this lines, like:
QHBoxLayout Layout;
//...
Layout.addWidget(& MimimizeBt, 2, Qt::AlignRight | Qt::AlignTop);
Layout.addWidget(& CloseBt, 0, Qt::AlignRight | Qt::AlignTop);
Or you can attach another print-screen so that we will see what is going on.
never mind my code now looks like this
#include <QtGui>
//--------------------------------------------------------------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
QApplication App(argc, argv);
QWidget MainWnd;
QHBoxLayout Layout;
QPushButton CloseBt;
QPushButton MimimizeBt;
// ----
CloseBt.setText("X");
// ----
MimimizeBt.setText("_");
// ----
Layout.setSpacing(1);
Layout.setAlignment(Qt::AlignTop | Qt::AlignRight);
Layout.addWidget(& MimimizeBt);
Layout.addWidget(& CloseBt);
// ----
QObject::connect(& MimimizeBt, SIGNAL(clicked()), &MainWnd, SLOT(showMinimized()));
QObject::connect(& CloseBt, SIGNAL(clicked()), &MainWnd, SLOT(close()));
MainWnd.setLayout(& Layout);
MainWnd.setWindowFlags(Qt::FramelessWindowHint);
MainWnd.resize(800, 600);
MainWnd.show();
// ----
return App.exec();
}
//--------------------------------------------------------------------------------------------------------------------------------------------
and its looks like this:
http://i53.tinypic.com/2lmsyf4.jpg
how can i change size of buttons? so they will be more smaller
thanks again
Zlatomir
2nd May 2011, 15:36
You can use setMaximumWidth(...) (http://doc.qt.nokia.com/latest/qwidget.html#maximumWidth-prop)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.