KDE/Qt Tips 004

来源:互联网 发布:免费打电话软件推荐 编辑:程序博客网 时间:2024/06/10 11:20
布局
QLabel
main
关于布局
QVBoxLayout
QHBoxLayout
QGridLayout
Inherits QBoxLayout.
常用的函数:
QLayout ( QWidget * parent, int margin = 0, int spacing = -1, const char * name = 0 )
QLayout ( QLayout * parentLayout, int spacing = -1, const char * name = 0 )
void addChildLayout ( QLayout * l )
The margin is the number of pixels between the edge of the widget and its managed children. The spacing is the default number of pixels between neighboring children. If spacing is -1 the value of margin is used for spacing.

void QLayout::setMenuBar ( QMenuBar * w ) [virtual]
Makes the geometry manager take account of the menu bar w. All child widgets are placed below the bottom edge of the menu bar.
bool QLayout::activate ()
Redoes the layout for mainWidget(). You should generally not need to call this because it is automatically called at the most appropriate times.
However, if you set up a QLayout for a visible widget without resizing that widget, you will need to call this function in order to lay it out.

QBoxLayout ( QWidget * parent, Direction d, int margin = 0, int spacing = -1, const char * name = 0 )
QBoxLayout ( QLayout * parentLayout, Direction d, int spacing = -1, const char *name = 0 )
Inherits QLayout.
Inherited by QHBoxLayout and QVBoxLayout.
void addWidget ( QWidget * widget, int stretch = 0, int alignment = 0 )
void addLayout ( QLayout * layout, int stretch = 0 )

bool setStretchFactor ( QWidget * w, int stretch )
bool setStretchFactor ( QLayout * l, int stretch )

QHBoxLayout ( QWidget * parent, int margin = 0, int spacing = -1, const char * name = 0 )
QHBoxLayout ( QLayout * parentLayout, int spacing = -1, const char * name = 0 )

关于QLabel
setScaledContents( TRUE );//可以使Label内的图像随label大小而拉伸,一直填满label
setPaletteBackgroundPixmap( pix );//拉伸时自动填充label
setPixmap(pix);//拉伸时大小不变

main函数中若
mainWin = new MyWidget;
app.setMainWidget(mainWin);
return app.exec;
程序关闭时不会调MyWidget;的析构函数
除非在app.exec后加上
delete mainWin;
或者
MyWidget mainWin;
app.setMainWidget(&mainWin);
return app.exec;