本文整理汇总了C++中QScrollBar::height方法的典型用法代码示例。如果您正苦于以下问题:C++ QScrollBar::height方法的具体用法?C++ QScrollBar::height怎么用?C++ QScrollBar::height使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScrollBar
的用法示例。
在下文中一共展示了QScrollBar::height方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isBlockVisible
bool VMdEditor::isBlockVisible(const QTextBlock &p_block)
{
if (!p_block.isValid() || !p_block.isVisible()) {
return false;
}
QScrollBar *vbar = verticalScrollBar();
if (!vbar || !vbar->isVisible()) {
// No vertical scrollbar.
return true;
}
int height = rect().height();
QScrollBar *hbar = horizontalScrollBar();
if (hbar && hbar->isVisible()) {
height -= hbar->height();
}
QAbstractTextDocumentLayout *layout = document()->documentLayout();
QRectF rect = layout->blockBoundingRect(p_block);
int y = GETVISUALOFFSETY;
int rectHeight = (int)rect.height();
return (y >= 0 && y < height) || (y < 0 && y + rectHeight > 0);
}
示例2: calculPopupGeometry
void pTreeComboBox::calculPopupGeometry()
{
if ( !mView ) {
return;
}
QStyle * const style = this->style();
// set current item and select it
view()->selectionModel()->setCurrentIndex( mCurrentIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
QFrame* container = mFrame;
QStyleOptionComboBox opt;
initStyleOption( &opt );
QRect listRect( style->subControlRect( QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxListBoxPopup, this ) );
QRect screen = popupGeometry( QApplication::desktop()->screenNumber( this ) );
QPoint below = mapToGlobal( listRect.bottomLeft() );
int belowHeight = screen.bottom() -below.y();
QPoint above = mapToGlobal( listRect.topLeft() );
int aboveHeight = above.y() -screen.y();
bool boundToScreen = !window()->testAttribute( Qt::WA_DontShowOnScreen );
listRect.moveTopLeft( mapToGlobal( rect().bottomLeft() ) );
listRect.setSize( QSize(
qMax( qMax( view()->viewport()->width(), mFrame->width() ), width() )
,
qMax( view()->viewport()->height(), mFrame->height() )
) );
const bool usePopup = style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this );
{
int listHeight = 0;
int count = 0;
QStack<QModelIndex> toCheck;
toCheck.push( view()->rootIndex() );
#ifndef QT_NO_TREEVIEW
QTreeView* treeView = qobject_cast<QTreeView*>( view() );
if ( treeView && treeView->header() && !treeView->header()->isHidden() )
listHeight += treeView->header()->height();
#endif
while ( !toCheck.isEmpty() ) {
QModelIndex parent = toCheck.pop();
for ( int i = 0; i < model()->rowCount( parent ); ++i ) {
QModelIndex idx = model()->index( i, mModelColumn, parent );
if ( !idx.isValid() )
continue;
listHeight += view()->visualRect( idx ).height();
#ifndef QT_NO_TREEVIEW
if ( model()->hasChildren( idx ) && treeView && treeView->isExpanded( idx ) )
toCheck.push( idx );
#endif
++count;
if ( !usePopup && count > mMaxVisibleItems ) {
toCheck.clear();
break;
}
}
}
listRect.setHeight( listHeight );
}
{
// add the spacing for the grid on the top and the bottom;
int heightMargin = 0;
// add the frame of the container
int marginTop, marginBottom;
container->getContentsMargins( 0, &marginTop, 0, &marginBottom );
heightMargin += marginTop +marginBottom;
//add the frame of the view
view()->getContentsMargins( 0, &marginTop, 0, &marginBottom );
marginTop += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top*/;
marginBottom += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom*/;
heightMargin += marginTop +marginBottom;
listRect.setHeight( listRect.height() +heightMargin );
}
// Add space for margin at top and bottom if the style wants it.
if ( usePopup )
listRect.setHeight( listRect.height() +style->pixelMetric( QStyle::PM_MenuVMargin, &opt, this ) *2 );
// Make sure the popup is wide enough to display its contents.
if ( usePopup ) {
const int diff = sizeHint().width() /*d->computeWidthHint()*/ -width();
if ( diff > 0 )
listRect.setWidth( listRect.width() +diff );
}
//we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
container->layout()->activate();
//takes account of the minimum/maximum size of the container
listRect.setSize( listRect.size().expandedTo(container->minimumSize())
.boundedTo(container->maximumSize()));
// make sure the widget fits on screen
if (boundToScreen) {
if (listRect.width() > screen.width() )
listRect.setWidth(screen.width());
if (/*mapToGlobal(*/listRect/*.bottomRight())*/.x() > screen.right()) {
//.........这里部分代码省略.........
示例3: resizePopup
// -------------------------------------------------------------------------
void ctkTreeComboBox::resizePopup()
{
// copied from QComboBox.cpp
Q_D(ctkTreeComboBox);
QStyle * const style = this->style();
QWidget* container = qobject_cast<QWidget*>(this->view()->parent());
QStyleOptionComboBox opt;
this->initStyleOption(&opt);
QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
QStyle::SC_ComboBoxListBoxPopup, this));
QRect screen = QApplication::desktop()->availableGeometry(
QApplication::desktop()->screenNumber(this));
QPoint below = this->mapToGlobal(listRect.bottomLeft());
int belowHeight = screen.bottom() - below.y();
QPoint above = this->mapToGlobal(listRect.topLeft());
int aboveHeight = above.y() - screen.y();
bool boundToScreen = !this->window()->testAttribute(Qt::WA_DontShowOnScreen);
const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);
{
int listHeight = 0;
int count = 0;
QStack<QModelIndex> toCheck;
toCheck.push(this->view()->rootIndex());
#ifndef QT_NO_TREEVIEW
QTreeView *treeView = qobject_cast<QTreeView*>(this->view());
if (treeView && treeView->header() && !treeView->header()->isHidden())
listHeight += treeView->header()->height();
#endif
while (!toCheck.isEmpty())
{
QModelIndex parent = toCheck.pop();
for (int i = 0; i < this->model()->rowCount(parent); ++i)
{
QModelIndex idx = this->model()->index(i, this->modelColumn(), parent);
if (!idx.isValid())
{
continue;
}
listHeight += this->view()->visualRect(idx).height(); /* + container->spacing() */;
#ifndef QT_NO_TREEVIEW
if (this->model()->hasChildren(idx) && treeView && treeView->isExpanded(idx))
{
toCheck.push(idx);
}
#endif
++count;
if (!usePopup && count > this->maxVisibleItems())
{
toCheck.clear();
break;
}
}
}
listRect.setHeight(listHeight);
}
{
// add the spacing for the grid on the top and the bottom;
int heightMargin = 0;//2*container->spacing();
// add the frame of the container
int marginTop, marginBottom;
container->getContentsMargins(0, &marginTop, 0, &marginBottom);
heightMargin += marginTop + marginBottom;
//add the frame of the view
this->view()->getContentsMargins(0, &marginTop, 0, &marginBottom);
//marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->top;
//marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->bottom;
heightMargin += marginTop + marginBottom;
listRect.setHeight(listRect.height() + heightMargin);
}
// Add space for margin at top and bottom if the style wants it.
if (usePopup)
{
listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
}
// Make sure the popup is wide enough to display its contents.
if (usePopup)
{
const int diff = d->computeWidthHint() - this->width();
if (diff > 0)
{
listRect.setWidth(listRect.width() + diff);
}
}
//we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
container->layout()->activate();
//takes account of the minimum/maximum size of the container
listRect.setSize( listRect.size().expandedTo(container->minimumSize())
.boundedTo(container->maximumSize()));
// make sure the widget fits on screen
//.........这里部分代码省略.........
示例4: makeBlockVisible
void VMdEditor::makeBlockVisible(const QTextBlock &p_block)
{
if (!p_block.isValid() || !p_block.isVisible()) {
return;
}
QScrollBar *vbar = verticalScrollBar();
if (!vbar || (vbar->minimum() == vbar->maximum())) {
// No vertical scrollbar. No need to scroll.
return;
}
int height = rect().height();
QScrollBar *hbar = horizontalScrollBar();
if (hbar && (hbar->minimum() != hbar->maximum())) {
height -= hbar->height();
}
bool moved = false;
QAbstractTextDocumentLayout *layout = document()->documentLayout();
QRectF rect = layout->blockBoundingRect(p_block);
int y = GETVISUALOFFSETY;
int rectHeight = (int)rect.height();
// Handle the case rectHeight >= height.
if (rectHeight >= height) {
if (y < 0) {
// Need to scroll up.
while (y + rectHeight < height && vbar->value() > vbar->minimum()) {
moved = true;
vbar->setValue(vbar->value() - vbar->singleStep());
rect = layout->blockBoundingRect(p_block);
rectHeight = (int)rect.height();
y = GETVISUALOFFSETY;
}
} else if (y > 0) {
// Need to scroll down.
while (y > 0 && vbar->value() < vbar->maximum()) {
moved = true;
vbar->setValue(vbar->value() + vbar->singleStep());
rect = layout->blockBoundingRect(p_block);
rectHeight = (int)rect.height();
y = GETVISUALOFFSETY;
}
if (y < 0) {
// One step back.
moved = true;
vbar->setValue(vbar->value() - vbar->singleStep());
}
}
if (moved) {
qDebug() << "scroll to make huge block visible";
}
return;
}
while (y < 0 && vbar->value() > vbar->minimum()) {
moved = true;
vbar->setValue(vbar->value() - vbar->singleStep());
rect = layout->blockBoundingRect(p_block);
rectHeight = (int)rect.height();
y = GETVISUALOFFSETY;
}
if (moved) {
qDebug() << "scroll page down to make block visible";
return;
}
while (y + rectHeight > height && vbar->value() < vbar->maximum()) {
moved = true;
vbar->setValue(vbar->value() + vbar->singleStep());
rect = layout->blockBoundingRect(p_block);
rectHeight = (int)rect.height();
y = GETVISUALOFFSETY;
}
if (moved) {
qDebug() << "scroll page up to make block visible";
}
}