本文整理汇总了C++中QScrollBar::singleStep方法的典型用法代码示例。如果您正苦于以下问题:C++ QScrollBar::singleStep方法的具体用法?C++ QScrollBar::singleStep怎么用?C++ QScrollBar::singleStep使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScrollBar
的用法示例。
在下文中一共展示了QScrollBar::singleStep方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
bool ChatWindow::eventFilter(QObject* watched, QEvent* e)
{
if(e->type() == QEvent::KeyPress)
{
QKeyEvent* ke = static_cast<QKeyEvent*>(e);
bool scrollMod = (Preferences::self()->useMultiRowInputBox() ? false : (ke->modifiers() == Qt::ShiftModifier));
if(ke->key() == Qt::Key_Up && scrollMod)
{
if(textView)
{
QScrollBar* sbar = textView->verticalScrollBar();
sbar->setValue(sbar->value() - sbar->singleStep());
}
return true;
}
else if(ke->key() == Qt::Key_Down && scrollMod)
{
if(textView)
{
QScrollBar* sbar = textView->verticalScrollBar();
sbar->setValue(sbar->value() + sbar->singleStep());
}
return true;
}
else if(ke->modifiers() == Qt::NoModifier && ke->key() == Qt::Key_PageUp)
{
if(textView)
{
QScrollBar* sbar = textView->verticalScrollBar();
sbar->setValue(sbar->value() - sbar->pageStep());
}
return true;
}
else if(ke->modifiers() == Qt::NoModifier && ke->key() == Qt::Key_PageDown)
{
if(textView)
{
QScrollBar* sbar = textView->verticalScrollBar();
sbar->setValue(sbar->value() + sbar->pageStep());
}
return true;
}
}
return QWidget::eventFilter(watched, e);
}
示例2: replaceScrollBar
/*! \internal
*/
void QAbstractScrollAreaPrivate::replaceScrollBar(QScrollBar *scrollBar,
Qt::Orientation orientation)
{
Q_Q(QAbstractScrollArea);
QAbstractScrollAreaScrollBarContainer *container = scrollBarContainers[orientation];
bool horizontal = (orientation == Qt::Horizontal);
QScrollBar *oldBar = horizontal ? hbar : vbar;
if (horizontal)
hbar = scrollBar;
else
vbar = scrollBar;
scrollBar->setParent(container);
container->scrollBar = scrollBar;
container->layout->removeWidget(oldBar);
container->layout->insertWidget(0, scrollBar);
scrollBar->setVisible(oldBar->isVisibleTo(container));
scrollBar->setInvertedAppearance(oldBar->invertedAppearance());
scrollBar->setInvertedControls(oldBar->invertedControls());
scrollBar->setRange(oldBar->minimum(), oldBar->maximum());
scrollBar->setOrientation(oldBar->orientation());
scrollBar->setPageStep(oldBar->pageStep());
scrollBar->setSingleStep(oldBar->singleStep());
scrollBar->setSliderDown(oldBar->isSliderDown());
scrollBar->setSliderPosition(oldBar->sliderPosition());
scrollBar->setTracking(oldBar->hasTracking());
scrollBar->setValue(oldBar->value());
delete oldBar;
QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
q, horizontal ? SLOT(_q_hslide(int)) : SLOT(_q_vslide(int)));
QObject::connect(scrollBar, SIGNAL(rangeChanged(int,int)),
q, SLOT(_q_showOrHideScrollBars()), Qt::QueuedConnection);
}
示例3: QGraphicsProxyWidget
TabsView::TabsView( QGraphicsWidget *parent )
: QGraphicsProxyWidget( parent )
{
// tree view which holds the collection of fetched tabs
m_treeView = new TabsTreeView( 0 );
connect( m_treeView, SIGNAL( clicked( const QModelIndex & ) ),
this, SLOT( itemClicked( const QModelIndex & ) ) );
m_model = new QStandardItemModel();
m_model->setColumnCount( 1 );
m_treeView->setModel( m_model );
m_treeProxy = new QGraphicsProxyWidget( this );
m_treeProxy->setWidget( m_treeView );
// the textbrowser widget to display the tabs
m_tabTextBrowser = new Plasma::TextBrowser( );
KTextBrowser *browserWidget = m_tabTextBrowser->nativeWidget();
browserWidget->setFrameShape( QFrame::StyledPanel );
browserWidget->setAttribute( Qt::WA_NoSystemBackground );
browserWidget->setOpenExternalLinks( true );
browserWidget->setUndoRedoEnabled( true );
browserWidget->setAutoFillBackground( false );
browserWidget->setWordWrapMode( QTextOption::NoWrap );
browserWidget->viewport()->setAutoFillBackground( true );
browserWidget->viewport()->setAttribute( Qt::WA_NoSystemBackground );
browserWidget->setTextInteractionFlags( Qt::TextBrowserInteraction | Qt::TextSelectableByKeyboard );
QScrollBar *treeScrollBar = m_treeView->verticalScrollBar();
m_scrollBar = new Plasma::ScrollBar( this );
m_scrollBar->setFocusPolicy( Qt::NoFocus );
// synchronize scrollbars
connect( treeScrollBar, SIGNAL( rangeChanged( int, int ) ), SLOT( slotScrollBarRangeChanged( int, int ) ) );
connect( treeScrollBar, SIGNAL( valueChanged( int ) ), m_scrollBar, SLOT( setValue( int ) ) );
connect( m_scrollBar, SIGNAL( valueChanged( int ) ), treeScrollBar, SLOT( setValue( int ) ) );
m_scrollBar->setRange( treeScrollBar->minimum(), treeScrollBar->maximum() );
m_scrollBar->setPageStep( treeScrollBar->pageStep() );
m_scrollBar->setSingleStep( treeScrollBar->singleStep() );
// arrange textbrowser and treeview in a horizontal layout
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout( Qt::Horizontal );
layout->addItem( m_treeProxy );
layout->addItem( m_scrollBar );
layout->addItem( m_tabTextBrowser );
layout->setSpacing( 2 );
layout->setContentsMargins( 0, 0, 0, 0 );
setLayout( layout );
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
updateScrollBarVisibility();
}
示例4: updateScrollBar
void QConsolePrivate::updateScrollBar (void)
{
m_scrollBar->setMinimum (0);
if (m_bufferSize.height () > m_consoleRect.height ())
m_scrollBar->setMaximum (m_bufferSize.height () - m_consoleRect.height ());
else
m_scrollBar->setMaximum (0);
m_scrollBar->setSingleStep (1);
m_scrollBar->setPageStep (m_consoleRect.height ());
m_scrollBar->setValue (m_consoleRect.top ());
log ("Scrollbar parameters updated: %d/%d/%d/%d\n",
m_scrollBar->minimum (), m_scrollBar->maximum (),
m_scrollBar->singleStep (), m_scrollBar->pageStep ());
}
示例5: verticalScrollBar
void
chat::_cond_scroll_prepare() {
// Chack that if the last line before new text is entered is not visible,
// then do not do the scrolling because it means user has scrolled the
// buffer back and wants to view older text.
QScrollBar *vbar = verticalScrollBar();
int maximum = vbar->maximum();
int value = vbar->value();
int single_step = vbar->singleStep();
_saved_pre_insert_vertical_value = value;
_allow_scroll = (maximum - value < single_step);
ACE_DEBUG((LM_DEBUG, "chat::_cond_scroll_prepare: max %d, val %d, singleStep %d, allow_scroll: %d\n", maximum, value, single_step, _allow_scroll));
// Ensure text is inserted at the end of the buffer
QTextCursor c = this->textCursor();
c.movePosition(QTextCursor::End);
setTextCursor(c);
}
示例6: ModifyScrollBars
// Set the extent of the vertical and horizontal scrollbars and return true if
// the view needs re-drawing.
bool QsciScintillaQt::ModifyScrollBars(int nMax,int nPage)
{
bool modified = false;
QScrollBar *sb;
int vNewPage = nPage;
int vNewMax = nMax - vNewPage + 1;
if (vMax != vNewMax || vPage != vNewPage)
{
vMax = vNewMax;
vPage = vNewPage;
modified = true;
sb = qsb->verticalScrollBar();
sb->setMaximum(vMax);
sb->setPageStep(vPage);
}
int hNewPage = GetTextRectangle().Width();
int hNewMax = (scrollWidth > hNewPage) ? scrollWidth - hNewPage : 0;
int charWidth = vs.styles[STYLE_DEFAULT].aveCharWidth;
sb = qsb->horizontalScrollBar();
if (hMax != hNewMax || hPage != hNewPage || sb->singleStep() != charWidth)
{
hMax = hNewMax;
hPage = hNewPage;
modified = true;
sb->setMaximum(hMax);
sb->setPageStep(hPage);
sb->setSingleStep(charWidth);
}
return modified;
}
示例7: scrollBarReleased
void ClientTextEdit::scrollBarReleased() {
// if(action == QAbstractSlider::SliderReleased) {
QScrollBar* sb = verticalScrollBar();
int val = sb->value()+sb->pageStep();
int singleStep = sb->singleStep();
qDebug() << "* singleStep is:" << singleStep;
//int docSize = sb->maximum() - sb->minimum() + sb->pageStep();
if(val%singleStep != 0) {
qDebug() << "* val is:" << val;
// here's what's left over
int newVal = val/singleStep;
int pixels = newVal*singleStep;
qDebug() << "* newVal is:" << newVal;
if(val-pixels < singleStep/2) {
val = pixels;
} else {
val = pixels + singleStep;
}
}
sb->setSliderPosition(val-sb->pageStep());
qDebug() << "* set slider position to" << val;
// }
}
示例8: moveDefinicio
void Main::moveDefinicio(QEvent *event)
{
int type = event->type();
int step,pagestep;
QScrollBar *bar;
bar=ui.definicio->verticalScrollBar();
step=bar->singleStep();
pagestep=bar->pageStep();
if (type == QEvent::User+Auxiliar::KeyDown()) {
bar->setSliderPosition(bar->sliderPosition()+step);
}
else if (type == QEvent::User+Auxiliar::KeyUp()) {
bar->setSliderPosition(bar->sliderPosition()-step);
}
else if (type == QEvent::User+Auxiliar::KeyNextPage()) {
bar->setSliderPosition(bar->sliderPosition()+pagestep);
}
else if (type == QEvent::User+Auxiliar::KeyPrevPage()) {
bar->setSliderPosition(bar->sliderPosition()-pagestep);
}
}
示例9: log
//.........这里部分代码省略.........
if (!ui->debugCheckBox->isChecked()) {
return;
}
// print debug messages to stderr if in release-mode but debug
// logging is enabled in the log panel
#ifndef QT_DEBUG
fprintf(stderr, "Debug: %s\n", text.toLocal8Bit().constData());
#endif
// gray
color = QColor(98, 98, 98);
break;
case InfoLogType:
if (!ui->infoCheckBox->isChecked()) {
return;
}
color = QColor(Qt::darkBlue);
break;
case WarningLogType:
if (!ui->warningCheckBox->isChecked()) {
return;
}
// this is a "fix" for crashes that occur when a network goes away
// and this message should be printed, I haven't managed to get
// around this crash with other methods
if (text.contains(
"/org/freedesktop/NetworkManager/ActiveConnection")) {
return;
}
// orange
color = QColor(255, 128, 0);
break;
case CriticalLogType:
if (!ui->criticalCheckBox->isChecked()) {
return;
}
// light red
color = QColor(192, 0, 0);
break;
case FatalLogType:
if (!ui->fatalCheckBox->isChecked()) {
return;
}
// lighter red
color = QColor(210, 0, 0);
break;
case StatusLogType:
if (!ui->statusCheckBox->isChecked()) {
return;
}
// green
color = QColor(0, 128, 0);
break;
case ScriptingLogType:
if (!ui->scriptingCheckBox->isChecked()) {
return;
}
// blue
color = QColor(0, 102, 255);
break;
}
QDateTime dateTime = QDateTime::currentDateTime();
// text.prepend("[" + dateTime.toString("hh:mm:ss") + "] [" + type + "] ");
// text.append("\n");
QString html = QString("<div style=\"color: %1\">[%2] [%3] %4</div>")
.arg(color.name(), dateTime.toString("hh:mm:ss"), type,
text.toHtmlEscaped());
QScrollBar *scrollBar = ui->logTextEdit->verticalScrollBar();
// we want to scroll down later if the scrollbar is near the bottom
bool scrollDown = scrollBar->value() >=
(scrollBar->maximum() - scrollBar->singleStep());
// return if logging isn't enabled any more
if (!qApp->property("loggingEnabled").toBool()) {
return;
}
const QSignalBlocker blocker(ui->logTextEdit);
Q_UNUSED(blocker);
// insert the text at the end
ui->logTextEdit->appendHtml(html.trimmed());
if (scrollDown) {
// move the text cursor to the end
ui->logTextEdit->moveCursor(QTextCursor::End);
// scrollBar->setValue(scrollBar->maximum());
}
#else
Q_UNUSED(logType);
Q_UNUSED(text);
#endif
}
示例10: log
/**
* Adds a log entry
*/
void LogWidget::log(LogType logType, QString text) {
#ifndef INTEGRATION_TESTS
// return if logging wasn't enabled
if (!qApp->property("loggingEnabled").toBool()) {
return;
}
QString type = "";
QColor color = QColor(Qt::black);
switch (logType) {
case DebugLogType:
if (!ui->debugCheckBox->isChecked()) {
return;
}
type = "debug";
// gray
color = QColor(98, 98, 98);
break;
case InfoLogType:
if (!ui->infoCheckBox->isChecked()) {
return;
}
type = "info";
color = QColor(Qt::darkBlue);
break;
case WarningLogType:
if (!ui->warningCheckBox->isChecked()) {
return;
}
type = "warning";
// orange
color = QColor(255, 128, 0);
break;
case CriticalLogType:
if (!ui->criticalCheckBox->isChecked()) {
return;
}
type = "critical";
// light red
color = QColor(192, 0, 0);
break;
case FatalLogType:
if (!ui->fatalCheckBox->isChecked()) {
return;
}
type = "fatal";
// lighter red
color = QColor(210, 0, 0);
break;
case StatusLogType:
if (!ui->statusCheckBox->isChecked()) {
return;
}
type = "status";
// green
color = QColor(0, 128, 0);
break;
case ScriptingLogType:
if (!ui->scriptingCheckBox->isChecked()) {
return;
}
type = "scripting";
// blue
color = QColor(0, 102, 255);
break;
default:
type = "unknown";
break;
}
QDateTime dateTime = QDateTime::currentDateTime();
// text.prepend("[" + dateTime.toString("hh:mm:ss") + "] [" + type + "] ");
// text.append("\n");
QString html = QString("<div style=\"color: %1\">[%2] [%3] %4</div><br />")
.arg(color.name(), dateTime.toString("hh:mm:ss"), type,
text.toHtmlEscaped());
QScrollBar *scrollBar = ui->logTextEdit->verticalScrollBar();
// we want to scroll down later if the scrollbar is near the end bottom
bool scrollDown = scrollBar->value() >=
(scrollBar->maximum() - scrollBar->singleStep());
QTextCursor c = ui->logTextEdit->textCursor();
// insert the text at the end
c.movePosition(QTextCursor::End);
c.insertHtml(html);
if (scrollDown) {
// move the text cursor to the end
ui->logTextEdit->moveCursor(QTextCursor::End);
}
#else
Q_UNUSED(logType);
//.........这里部分代码省略.........
示例11: 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";
}
}