I've got a QGraphicsView with a vertical Scrollbar, but the problem is that when I run my app, the scrollbar position is set to the center of the QGraphicsView.
How can I set it to the top by default ?
I tried to use :
view->verticalScrollBar()->setValue(0);
But it doesn't change a thing. However, I tried this too :
view->verticalScrollBar()->setValue(1);
And it does change the Scrollbar Position to the top, but not at its minimum.
Related
How to change the position of the Vertical Scrollbar of a window?
I'm referring to the position in xy, for example set it in the middle of the window instead of the edges.
You cannot reposition a scrollbar that is built-in to a window. You will have to disable the native scrollbar (remove the window's WS_HSCROLL/WS_VSCROLL style) and then create a separate ScrollBar control as a child of the window. Then you can position that child wherever you want, using the x/y parameters of CreateWindow/Ex() or SetWindowPos().
I'm working on Qt interface now and I have a widget in the center of the window, the widget has fixed size. when I resize the window with mouse the widget stays at the left of the window. I don't want this, but I want to stay it in the center.
I tried this;
listWidget->setFixedSize(640,480);
listWidget->adjustSize();
layout->addWidget(listWidget,Qt::AlignCenter);
but it doesn't do that.
can you help me?
This code works fine for me :
QGridLayout * layout = new QGridLayout(this);
QListWidget * listWidget = new QListWidget(this);
listWidget->setFixedSize(640,480);
listWidget->adjustSize();
layout->addWidget(listWidget,0, 0,Qt::AlignCenter);
But an other way is to put two vertical spacers and two horizontal spacers in the layout. One should be placed at top most, the other one at the bottom, one on the left and one on the right :
im adding QGraphicsLayoutItem in a QGraphicsWidget in run time using QGraphicsLinearLayout.
i have to add more items to the layout that exceeds the height of the viewport height and items shown outside the viewport area.so is it possible to pan or scroll in QGraphicsWidget like QGraphicsView. QGraphicsView i can pan using centerOn and showing only a visible rect.
the normal view
and when more item added
I have a QGraphicsView that renders my game. This view fills the entire screen at all times. In the top right I have another QGraphicsView which I'm using as a mini-map; it sits over the game view. I want this mini-map to be anchored to the top right of the screen, always maintaining its size. This code almost works, except that the left side of the mini-map never changes (which is to be expected).
void MainWindow::resizeEvent(QResizeEvent *event)
{
mainWindow->graphicsView->resize(event->size().width(), event->size().height());
QRect newRect(mainWindow->miniMapGraphicsView->geometry());
newRect.setRight(event->size().width() - 20);
mainWindow->miniMapGraphicsView->setGeometry(newRect);
}
How can I do this?
When you want to position widgets in a certain way, layouts are usually the best way to do it.
Add a QFormLayout to your graphicsView and set its layoutDirection to Qt::RightToLeft. Then add your miniMapGraphicsView to the layout. Editing the properties of the mini map, set its horizontal and vertical sizePolicy to Fixed and set its minimumSize and maximumSize to the dimensions you would like it to be.
An alternative would be to use a QGridLayout and use horizontal and vertical spacers to push the mini map to any corner of the view.
NOTE: Layouts have margins set by default so if you want your widgets to align snugly at the edges, zero them out.
I am trying to show a picture in it's full view using QGraphicsScene. But when ever I put the QgraphicsScene inside the QGraphicsView, I am getting a scroll bar. I tried so many ways But all are went to veins. So can anybody tell me how to obtain the full view without the scrollbar.
You might be getting scrollbars because the scene is larger than the usable area within the graphics view. By default, a QGraphicsView comes with a 1-pixel margin. To fix this, you can try:
QRect rcontent = graphicsView.contentsRect();
graphicsView.setSceneRect(0, 0, rcontent.width(), rcontent.height());
I had been getting scrollbars because I was manually setting the scene rect to the size of the graphics item I was adding -- which was as large as the QGraphicsView widget. I wasn't taking into account the margin.
QGraphicsView v;
v.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
v.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
To adjust the scrolling programmatically once these have been hidden, use one of the overloads of v.ensureVisible().