QWidget - Always resizing by window size - qt

I have a QTextEdit Control and I want it to resize widh window size always.
My solution is using a timer, but that won't be really elegant, so I thought, there must be a property.
Could you help me? Uncle Google wasn't any help.
Thanks in advance.
P.S.: I've tried to write in proper English, but I'm from germany, so there could be some mistakes. I hope you excuse it.

You could use your Windows resizeEvent to update the size of your QTextEdit.
Read more about the resizeEvent in the QWindow documentation: http://doc.qt.io/qt-5/qwindow.html#resizeEvent
And here is an Example:
void MyQWindow::resizeEvent(QResizeEvent* event)
{
QWindow::resizeEvent(event);
this->resizeTextEdit(); // In this function you update the size
}

Generaly, You can do that just with layouts, just wrap the QTextEdit inside one, (QVBoxLayout or QHBoxLayout for example).
Or if you have a specific case, you can use the method prposed by Mailerdaimon.

Related

QQuickwidget grab image outside window area

This is a sequel to another question here in which I was not precise while describing my goal.
As mentioned in the linked question, I wish to save a QML which is embedded in a QQuickWidget and it is larger than the window size. The QQuickWindow grabWindow() method captures only the window area and hence I tried the following code after I visually displayed it:
QQuickWidget* content..
content->setSource(QUrl("qml:/main.qml"));
QPixmap *pm = content->grab(QRect(QPoint(0,0),QSize(-1,-1));
pm->save("someFilename.png", 0, 100);
So, it is definitely not the issue of saving image after rendering. The used QML code is just a plain Rectangle. The proposed solutions in the previous question only grabs content falling within the window.
Any suggestions? Thanks! :)
Addendum:
I have tried the following but didn't work:
QImage paintdev(largeWidth, largeHeight, QImage:Format_RBG32);
content->render(paintdev, QPoint(0,0), QRegion(QRect(0,0,largeWidth, largeHeight), QWidget::DrawChildren);
paintdev.save(fileName, 0, 100);
This should by logic solve the issue of window size since there is no window. Any comments?
Ok, so I solved it by manually shifting the QML by the window height and saving all the images from the window captures and collate it to form the original image.
Not too much work though, but I am still mystified by the QWidget render() method which did not work.
Thanks for all the replies!
If your QML content is larger than the window size, the part that is out of screen is not drawn. Hence, there is no way to capture something out of screen, unless you use 2 monitors and extend view. This last approach would work.

How to add QWidget to a QGLWidget

What is currently the best way to add a QWidget to a QGLWidget as a child? In this case I want to add a QSlider to QGLWidget, however it seems like half the links on Google point to dead information now so it's tricky working out what the current way to achieve this is.
I did try creating a QSlider as a child and setting the geometry, but that didn't seem to do a lot.
Child widgets don't work with a QGLWidget, that's documented.
Use QOpenGLWidget and the child widgets will work fine. There's nothing special to do in this respect, simply add child widgets, layouts, etc., and it "just works".

Window flags not helping in mdiarea in Qt

I am using Qt and creating a GUI with multiple sub windows. I am using MDI Area for the same. I want to hide the top toolbar of mdi subwindow but using window flags is not helping.
I have tried writing the code as follows. First I tried for mdiarea and then for subwindow but neither worked.
mdiarea.setWindowsFlags(Qt::FramelessWindowHint);
subwindow.setWindowsFlags(Qt::FramelessWindowHint);
I have also tried using Qt::CustomizedWindowHint but even that is not helping. Please help me with this.
Thank You.
Try this:
mdiArea->addSubWindow(new QLabel("Qt::FramelessWindowHint"), Qt::FramelessWindowHint);
You don't want to set the MDI area itself as a frameless window, because it's a widget you likely have embedded in another window... it most likely already doesn't have a frame.
Your setting the 'subwindow' should work... but addSubWindow(myWidget) actually wraps the widget passed in in the real subwindow, so that's what was going wrong. Qt lets you pass in window flags as the second parameter of addSubWindow() and those flags go to the real subwindow.
Note that with a frameless window, you can't drag the window around to move it, or grab the edges to resize it, because there's nothing for you to grab onto!
If you just want the minimize and maximize buttons gone (but still want the close button), try passing Qt::Dialog instead.
Try also experimenting with these:
addSubWindow(new QLabel("Qt::Tool"), Qt::Tool);
addSubWindow(new QLabel("Qt::Tool|Qt::CustomizeWindowHint"), Qt::Tool|Qt::CustomizeWindowHint);
addSubWindow(new QLabel("Qt::Dialog"), Qt::Dialog);
I think Qt::Tool|Qt::CustomizeWindowHint is probably the best option (no buttons, but still movable and resizable - if you don't want it resizable, give it a fixed size (setFixedSize()).
Edit: Also try: Qt::CustomizeWindowHint|Qt::WindowTitleHint

Layout problems when switch from QWidget to QGraphicsItem

I'm switching a timeline viewer from QWidget to QGraphicsItem, because QWidget is too heavy, I got performance issues when there are thousand of QWidgets.
I need Layout Management. But I found QGraphicsItem was so light, that it did't support layout. I should use QGraphicsWidget, but there are many useful QGraphicsItem's subclasses, QGraphicsWidget doesn't have them. I think QGraphicsProxyWidget isn't the answer because it is already too slow when I using QWidgets...
So, is there any way to have a layout with any QGraphicsItem? Or is there a better solution?
QGraphicsLayout and QGraphicsLayoutItem are what you are looking for.
http://doc.qt.io/qt-4.8/qgraphicslayout.html
http://doc.qt.io/qt-4.8/qgraphicslayoutitem.html
Hope that helps.

Prevent Subwindow Resize

:D
I'm a Qt beginner and I have some problems.
Generally, all the languages and tools that have an GUI builder have for the window the "Resizeable" property.
Very well, I need to do the same in Qt:
No window resize, no resize pointer in hover the window's border, maximize button (in the window's title) disabled.
I'm tried to find something but unsuccessfully.
If someone help me, I'll be grateful.
Hug.
Sorry for my english. I'm brazilian. :)
In Qt Creator, I think you can create a non-resizable window by giving it the same minimum and maximum size.
Or you can do it by code using setFixedSize. In that case, just add this line in your window's constructor:
setFixedSize(size());
Use void QWidget::setWindowFlags ( Qt::WindowFlags type ). see enum Qt::WindowType for the list of flags you can play with.
For instance, setting Qt::Dialog | Qt::FramelessWindowHint should produce a windows without resize frame and no max/min button.

Resources