I have a QStackedWidget with a QLineEdit and a couple other widgets inside of it. This QStackedWidget is fairly dynamic - you can move it within its layout by clicking/dragging, change its current widget by right clicking it, etc.
I'd like to draw a simple, gray rectangle or a gray rounded rectangle around the QStackedWidget to let people know that the QLineEdit they're looking at is important. This drawn rectangle has to be able to follow the QStackedWidget so that it follows properly with the widget when I move it to other locations on-screen.
I've tried several approaches so far but they've all fallen short in some regard or another or it just wouldn't move with the widget. Can anyone show me how?
Depending on how your clicking/dragging is implemented, you should just be able to place the QStackedWidget inside another QFrame, or put a QFrame inside your QStackedWidget and put all the other controls inside the QFrame. QFrame's support drawing borders around them.
frame = QFrame()
frame.setFrameStyle(QFrame.StyledPanel)
frame.setLineWidth(2)
Related
I want to set up like the image bellow.
I want differents backgrounds color for QGraphicsView (say, same as window color) and QGraphicsScene (say, white). Also, I want that if some item is drawn out of the scene bounds that part is not rendered (the star 'any item' in img with legs cropped).
I have no clue how to set up this. I'm new on Qt.
PS: I'm using python, but you can examplify in c++ if you feel confortable.
Answering Jeremy Friesner
This is my code applying your tips:
scene = QtGui.QGraphicsScene(0, 0, 256, 256)
scene.setBackgroundBrush(QtGui.QBrush(scene.palette().color(QtGui.QPalette.Window)))
scene.addRect(scene.sceneRect(), QtGui.QPen(QtCore.Qt.NoPen), QtGui.QBrush(QtCore.Qt.white))
scene.addLine(0, 0, 356, 356)
view = QtGui.QGraphicsView(scene)
self.setCentralWidget(view) # we are in a QMainWindow
As you can see, I add a white QRect using scene bounds and a line a bit bigger than the scene bounds. This is the screenshot result of my app (the line is drawn out the scene too):
If the app size is lesser than scene bounds (ie, View <= Scene), the part out the scene is not rendered (bc scroll bars doesn't allow), but if the app is bigger (ie, View > Scene), then it is drawn. How to solve that?
I want different backgrounds color for QGraphicsView (say, same as
window color) and QGraphicsScene (say, white).
A QGraphicsScene object is never directly shown on the screen -- that is to say, it is not a subclass of QWidget and therefore there is no way to add it to your window's widget hierarchy. The only way to view the contents of a QGraphicsScene is by associating a QGraphicsView with the QGraphicsScene and adding the QGraphicsView to the widget hierarchy.
Given that, the solution to your problem should be to simply call setBackgroundBrush(window->palette().color(QPalette::Window)) on your QGraphicsScene object. The QGraphicsView will automatically reflect the background color of the QGraphicsScene.
If you then want the actual contents-area of the QGraphicsScene to be a different color (so that e.g. after you've zoomed out there is a window-background-colored border around a different background-color in the scene-area, as shown in your screenshot), you can get that effect by adding a QGraphicsRect item of the appropriate color and size (as given by QGraphicsScene::sceneRect()) to your scene. (Be sure to call setZValue() on it with a negative value so that it will remain behind all of the other objects in your scene!)
Also, I want that if some item is drawn out of the scene bounds that
part is not rendered (the star 'any item' in img with legs cropped).
AFAIK this is the usual behavior of the QGraphicsView -- any content that is outside the area defined by QGraphicsScene::sceneRect() is automatically clipped to that area. Are you seeing behavior that is different than that?
I am pretty new to GUI programming and to Qt itself, albeit having a lot of experience with HTML, CSS and JS (for UI design).
I am struggling to understand even the basics of designing custom data-display elements with Qt.
How can I create a scrollable area with custom rectangular data
displaying elements in it? I just want a scroll area with a
background image, and I want it to be populated with one or more
copies of the same data-viewing item which is to have 2 labels (like
twitter), a background image and some buttons.
I have been doing research for days now but could not find any examples.
Should I design a "widget" using Qt Designer? Then how do I load that
.ui as a widget and manipulate the labels on it?
For future reference a "very custom" way to do this would be as follows:
Create a QScrollArea.
Place a Widget inside it (QWidget for example)
Create a Layout for the QScrollArea's widget which will be the one scrolling.
Style QScrollArea and the Widget inside as desired.
Place custom widgets inside the layout.
Set autoscroll etc for the QScrollArea so it will resize and show elements as desired.
I am creating a Solitaire clone using Python's Tkinter window toolkit. My window contains a main canvas, and within the main canvas a series of widgets that inherit from Canvas that hold the cards. I have implemented a "Drag to Move" system where a user can click the mouse down to select a card in one of the inner canvases, drag it to a new canvas, and let go to place the card into the receiving canvas.
The Problem: I want to draw the cards in motion between the canvas on which they are drawn, and the canvas they are moving to, so the user can see them moving across the screen during the click and drag motion. When I try to draw cards in-between the canvases that I already have, they are always drawn behind, meaning I can only see cards through the padding around the inner canvases.
Here is an example where I drew several of them so the effect could be seen clearly, and the inner canvases are also clearly visible.
What I've Tried: I've tried to move the canvases back using Misc.lower(aCanvas), but i wasn't able to create the desired effect. I've also tried to design a custom overridden cursor, but it seems my cursor size is limited to 32px*32px, which is insufficient for the size of the card images I want to move.
My Question: How can I draw on top of a canvas that is inside of another canvas? If I can't, how would you solve this problem?
You cannot do what you want. Embedded widgets are always above the canvas items.
Why is it that you are embedding canvases insidebcanvases? Why not just use a single canvas?
I'm working with several widgets but the solution just won't come out. What I have is a series of buttons in series of QHBoxLayouts. Some buttons are hidden by default, but they will appear when needed. To solve space issues, all buttons have a minimum and maximum size so they always look well packed. Also I have a QTextEdit, visible by default, which is in a QVBoxLayout with the QHBoxLayout that hold the buttons
So the problem is this: When I hide the QTextEdit and show the other buttons, the window won't resize.
After searching I found that using self.ui.layout().setSizeConstraint(QtGui.QLayout.SetFixedSize) will do the trick, but the problem is that it takes the maximum size from all widgets, therefore I end a huge window. Doing self.ui.layout().setSizeConstraint(QtGui.QLayout.SetMinAndMaxSize) won't resize the window
I already tried using self.ui.resize(0,0), and when doing a self.ui.layout().update() I got False (which I find odd, http://doc.trolltech.com/4.6/qlayout.html#activate), and also tried to override sizeHint() but it keeps using the max size for all widgets.
Is there a way to resize the window and while taking care of the min and max size of a widget?
Thanks in advance
The answer was quite lame... Just needed to change the QVBoxLayout for a QGridLayout and use self.ui.layout().setSizeConstraint(QtGui.QLayout.SetFixedSize)
I am drawing inside a wx.Window using a PaintDC. I am drawing circles and stuff like that into that window. Problem is, sometimes the circles go outside the scope of the window. I want a scrollbar to automatically appear whenever the drawing gets too big. What do I do?
Use a wx.ScrolledWindow and set the size of the window as soon as your 'drawing go outside' the window with
SetVirtualSize(width,height)
If this size is bigger than the client size, then wx will show scrollbars. When drawing in the window make sure to use CalcUnscrolledPosition and CalcScrolledPosition
Here you can find some more information.