//header.cpp
ChemHeader
::ChemHeader(QWidget* parent,
const char* name
){
setBackgroundColor(Qt::white);
_headerLabel
= new QLabel(this);
_headerLabel->setText("Header");
_headerLabel->setBackgroundColor(Qt::white);
_headerText->setFocus();
_headerLabel->setGeometry(p.x()+10, p.y(), 45, 10);
QRect labelRect
= _headerLabel
->geometry
();
QPoint pp
= labelRect.
bottomLeft();
_headerText->setGeometry(p.x(), pp.y()+3, width(),height()-_headerLabel->height()-20);
_headerText->setHScrollBarMode(QScrollView::AlwaysOff);
_headerText
->setWrapPolicy
( QTextEdit::AtWordOrDocumentBoundary );
connect(_headerText, SIGNAL(textChanged()), this, SLOT( slotHeaderTextChanged()));
_headerNoOfLines = 2;
_headerMaxHeight = parent->height()/3;
//set Maximum height
_headerText->setMaximumHeight(_headerMaxHeight);
}
ChemHeader::~ChemHeader()
{}
//_headerText is a QTextEdit
void ChemHeader::slotHeaderTextChanged()
{
int noOfLines = _headerText->lines();
QFont f
= _headerText
->currentFont
();
int ht = fm.height();
if(noOfLines > _headerNoOfLines)
{
#ifdef _WIN32
resize(width(), height()+(ht) );
#else
resize(width(), height()+(ht+1) );
#endif
_headerText->resize(width(), height() -_headerLabel->height()-2);
_headerNoOfLines = noOfLines;
}
else if( _headerNoOfLines > 2 && noOfLines < _headerNoOfLines)
{
#ifdef _WIN32
resize(width(), height()-(ht) );
#else
resize(width(), height()-(ht+1) );
#endif
_headerText->resize(width(), height()-_headerLabel->height()-2);
_headerNoOfLines--;
}
}
{
if(height() > _headerMaxHeight)
{
}
}
//header.cpp
ChemHeader::ChemHeader(QWidget* parent, const char* name )
:QFrame ( parent, name )
{
setBackgroundColor(Qt::white);
_headerText = new QTextEdit(this);
_headerLabel = new QLabel(this);
_headerLabel->setText("Header");
_headerLabel->setBackgroundColor(Qt::white);
_headerText->setFocus();
QRect rec = frameRect();
QPoint p= rec.topLeft();
_headerLabel->setGeometry(p.x()+10, p.y(), 45, 10);
QRect labelRect = _headerLabel->geometry();
QPoint pp = labelRect.bottomLeft();
_headerText->setGeometry(p.x(), pp.y()+3, width(),height()-_headerLabel->height()-20);
_headerText->setHScrollBarMode(QScrollView::AlwaysOff);
_headerText->setWrapPolicy ( QTextEdit::AtWordOrDocumentBoundary );
connect(_headerText, SIGNAL(textChanged()), this, SLOT( slotHeaderTextChanged()));
_headerNoOfLines = 2;
_headerMaxHeight = parent->height()/3;
//set Maximum height
_headerText->setMaximumHeight(_headerMaxHeight);
}
ChemHeader::~ChemHeader()
{}
//_headerText is a QTextEdit
void ChemHeader::slotHeaderTextChanged()
{
int noOfLines = _headerText->lines();
QFont f = _headerText->currentFont();
QFontMetrics fm(f);
int ht = fm.height();
if(noOfLines > _headerNoOfLines)
{
#ifdef _WIN32
resize(width(), height()+(ht) );
#else
resize(width(), height()+(ht+1) );
#endif
_headerText->resize(width(), height() -_headerLabel->height()-2);
_headerNoOfLines = noOfLines;
}
else if( _headerNoOfLines > 2 && noOfLines < _headerNoOfLines)
{
#ifdef _WIN32
resize(width(), height()-(ht) );
#else
resize(width(), height()-(ht+1) );
#endif
_headerText->resize(width(), height()-_headerLabel->height()-2);
_headerNoOfLines--;
}
}
void ChemHeader::resizeEvent(QResizeEvent*)
{
if(height() > _headerMaxHeight)
{
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks