How to use QFrame in Qt
Article Metadata
Tested with
Devices(s): Symbian emulator
Compatibility
Platform(s): Qt
Article
Keywords: QFrame
Created: james1980
(31 Dec 2008)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Introduction
Qt provides the QFrame class which can be use to make a frame around the widget. You can make your application more attractive by using one of the type of frame given in this class.
QFrame is used as a base class for numerous widgets of Qt: QAbstractScrollArea, QLabel, QLCDNumber, QSplitter, QStackedWidget, and QToolBox. The examples of this page show the various frame around the label widget (QLabel).
Various Function
Frame Style
The frame style is defined by the combination of a frame shape and a shadow style.
label->setFrameStyle(QFrame::Box | QFrame::Raised); label->setLineWidth(2); label1->setFrameStyle(QFrame::Box | QFrame::Sunken); label1->setLineWidth(2);
Frame Shape
label1->setFrameShape(Qt::StyledPanel);
More information
For more functions and property visit: http://doc.trolltech.com/4.5/qframe.html
Code
#include <QApplication>
#include <QLabel>
#include <QFrame>
#include <QVBoxLayout>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *win = new QWidget;
QLabel *label = new QLabel("Box");
QLabel *label1 = new QLabel("Panel");
QLabel *label2 = new QLabel("Winpanel");
QLabel *label3 = new QLabel("H line");
QLabel *label4 = new QLabel("V line");
QLabel *label5 = new QLabel("Styled Panel");
label->setFrameStyle(QFrame::Box | QFrame::Raised);
label->setLineWidth(2);
label1->setFrameStyle(QFrame::Panel | QFrame::Raised);
label1->setLineWidth(2);
label2->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
label2->setLineWidth(2);
label3->setFrameStyle(QFrame::HLine | QFrame::Raised);
label3->setLineWidth(2);
label4->setFrameStyle(QFrame::VLine | QFrame::Raised);
label4->setLineWidth(2);
label5->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
label5->setLineWidth(2);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(label);
layout->addWidget(label1);
layout->addWidget(label2);
layout->addWidget(label3);
layout->addWidget(label4);
layout->addWidget(label5);
win->setLayout(layout);
win->show();
return app.exec();
}



This article is good.
The part "Various Function" is especially good because it presents each feature via a small example and the result in a screenshot. The final example is a bit long but it presents all the frame shapes, which is important.
There is one thing not so great in this article. It is supposed to present QFrame, and all the examples are made with QLabel. QLabel inherit QFrame so it is correct, but that should be made more explicit for the reader. One could wonder where is QFrame in those examples...
For me, this is "Reviewer Approved".
--elicec12 21:22, 20 September 2009 (UTC)
This article shows the use of QFrame in QT For S60.Using this class you can make you widget attractive.There are plenty of Frames available in QT.you can use any of this Frame.This frame is given on the link specified in article.
This frame style is specified by a frame shape and a shadow style. The frame shapes are NoFrame,Box,Panel,StyledPanel,Popup Panel,Win Panel,Tool Bar Panel,Menu Bar Panel,HLine and VLine;the shadow styles are Plain,Raised and Sunken.
setLineWidth(2) command shows the width of frame border.
--nayan_trivedi