Qt - Reddit
15 subscribers
302 photos
52 videos
4.3K links
News and discussion for the Qt Framework.

Subreddit: https://www.reddit.com/r/QtFramework

Powered by : @r_channels & @reddit2telegram
Download Telegram
I have an existing object with data. I want to draw this data to a widget. How?

So I have an object that has some data in it. I want to draw this data onto a widget.

I've created a new RenderWidget that inherits from QWidget. I've added a QWidget to my GUI in QT Creator and promoted it to this type. Inside my RenderWidget I've updated the `paintEvent` and I can see my widget being painted when I run the application.

How do I initialize this widget in my GUI with my object, so that the RenderWidget can read from it during the paintEvent?

Or am I supposed to create a new model inheriting from QAbstractItemModel, and somehow get that to the widget?

https://redd.it/1cqwse7
@qt_reddit
How to create Resize Handles for a QGraphicsItem?

Hey everyone.

I'm looking to create resize handles for any QGraphicsItem, similar to what you'd see in Photoshop. I'm wondering how I would accomplish this in PyQt. I need it to work for any QGraphicsItem so I don't have to subclass each item and apply logic internally. I was thinking about using QTransform for this, as it works for any item for scaling.

The handles need to work for any QGraphicsItem without subclassing each item and applying logic internally. I'm considering using QTransform because it works for any item for scaling. In summary, here's what I'm trying to achieve:

A screenshot of the resize handles in Adobe Illustrator

Any help or suggestions are greatly appreciated.

https://redd.it/1cr2cji
@qt_reddit
How to create rulers on sides of QGraphicsView in PyQt5?

Good day all. I am trying to achieve this in PyQt:

https://preview.redd.it/1yf01fmdko0d1.png?width=414&format=png&auto=webp&s=11c6a050c756687cc0947a4f7255c6b8e8628fdd

I have read countless Stack Overflow threads and searched Github, but all I have found are C++ versions of the rulers. I basically need a Python version of the rulers, I don't know if anybody has done this with PyQt. Any help is appreciated.

https://redd.it/1cszxfl
@qt_reddit
Error while installing QT on my desktop

I get this error while trying to install Qt on my desktop. It usually starts at around 2% of the installation process. Anything I can do to fix this?

https://preview.redd.it/y08isju6lr0d1.jpg?width=509&format=pjpg&auto=webp&s=a1fc2fb35346502e7d6139f4311fd8108bafd11e



https://redd.it/1ct9m6v
@qt_reddit
What's the easiest way to distribute a PyQt6 app for multiple OS?

Hi, I made a PyQt6 onefile app with PyInstaller and want to distribute it for Windows and MacOS. Is making a virtual machine for each OS and building it on them the best way, or are there better alternatives?

https://redd.it/1cu3676
@qt_reddit
Qt on lemmy?

Is there any Qt framework related community on lemmy? I can't find just by typing 'qt'. It didn't have auto suggestion like reddit.

https://redd.it/1cum9ek
@qt_reddit
Qt frameless window does not resize or move as expected on KDE

I have created a QMainWindow with the following window flags Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::BypassWindowManagerHint like so
BrowserWindow::BrowserWindow(QWidget parent, double width, double height): QMainWindow(parent), resizing(false){
this->resize(width, height);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::BypassWindowManagerHint);
this->setAttribute(Qt::WA_TranslucentBackground);
this->setMouseTracking(true);

//Implement Outer UI
QWidget
centralWidget = new QWidget(this);

//...widgets
centralWidget->setMouseTracking(true);


this->setCentralWidget(centralWidget);
}
Here is the code I've written to implement resizing
void BrowserWindow::mousePressEvent(QMouseEvent event){
if(event->button() == Qt::LeftButton && this->isEdgePosition(event->position())){
this->showNormal();
this->resizing = true;
this->maximized = false;
this->originalGeometry = this->geometry();
this->lastMousePosition = event->globalPosition();
this->currentEdgePosition = this->edgePosition(event->position());
}
QMainWindow::mousePressEvent(event);
}

void BrowserWindow::mouseMoveEvent(QMouseEvent
event){
switch(this->edgePosition(event->position())){
case WindowBoundary::TOP:
case WindowBoundary::BOTTOM:
this->setCursor(Qt::SizeVerCursor);
break;
//...the same for the other edges and corners
default:
this->setCursor(Qt::ArrowCursor);
}

if(this->resizing){
QPointF delta = event->globalPosition() - lastMousePosition;
QRect newGeometry = originalGeometry;

switch(this->currentEdgePosition){
case WindowBoundary::TOP:
newGeometry.setTop(originalGeometry.top() + delta.y());
break;
case WindowBoundary::BOTTOM:
newGeometry.setBottom(originalGeometry.bottom() + delta.y());
break;
case WindowBoundary::LEFT:
newGeometry.setLeft(originalGeometry.left() + delta.x());
break;
case WindowBoundary::RIGHT:
newGeometry.setRight(originalGeometry.right() + delta.x());
break;
case WindowBoundary::TOPLEFT:
newGeometry.setTop(
originalGeometry.top() + delta.y());
newGeometry.setLeft(originalGeometry.left() + delta.x());
break;
case WindowBoundary::TOP
RIGHT:
newGeometry.setTop(originalGeometry.top() + delta.y());
newGeometry.setRight(originalGeometry.right() + delta.x());
break;
case WindowBoundary::BOTTOMLEFT:
newGeometry.setBottom(originalGeometry.bottom() + delta.y());
newGeometry.setLeft(originalGeometry.left() + delta.x());
break;
case WindowBoundary::BOTTOM
RIGHT:
newGeometry.setBottom(originalGeometry.bottom() + delta.y());
newGeometry.setRight(originalGeometry.right() + delta.x());
break;
}

this->setGeometry(newGeometry);
}
QMainWindow::mouseMoveEvent(event);
}
Here is the code I use to move the window.
void TitleBar::mousePressEvent(QMouseEvent event){
this->moving = true;
this->originalPosition = event->globalPosition();
this->originalGeometry = this->window->geometry();
QWidget::mousePressEvent(event);
}

void TitleBar::mouseMoveEvent(QMouseEvent
event){
if(this->moving){
QPointF delta = event->globalPosition() - this->originalPosition;
QRect newGeometry = this->originalGeometry;

newGeometry.moveTopLeft(this->originalGeometry.topLeft() + delta.toPoint());

this->window->setGeometry(newGeometry);
}
}
Here is the issue: The window does not move when clicking and dragging on the titlebar on kde, and only the bottom, right and bottom right edges resize correctly. When resizing from the top, left or top left edges/corner, it resizes from the
bottom, right or bottom right edge/corner. I have tested the same code on pop os and it resizes and moves correctly.
What can I do to ensure the same behaviour on kwin and non kwin environments?

https://redd.it/1curpls
@qt_reddit
Cannot register namespace enum

I have an enum that I need to use both in QML and C++, so I followed a reddit post here and documentation:
[https://www.reddit.com/r/QtFramework/comments/18d1o5t/how\_can\_i\_expose\_an\_c\_enum\_to\_qml/](https://www.reddit.com/r/QtFramework/comments/18d1o5t/how_can_i_expose_an_c_enum_to_qml/)
[https://doc.qt.io/qt-6/qqmlengine.html#qmlRegisterUncreatableMetaObject](https://doc.qt.io/qt-6/qqmlengine.html#qmlRegisterUncreatableMetaObject)

so I have this code:

#include <QObject>

namespace AuthStatus
{
Q_NAMESPACE
enum class Status {
LoggedIn,
TokensPresent,
None
};
Q_ENUM_NS(Status)
}

qmlRegisterUncreatableMetaObject(AuthStatus::staticMetaObject, "socialhub", 1, 0, "AuthStatus", QStringLiteral("Access to enums only"));

but when I compile it with make, I get this error:

main.cpp:(.text+0xbbe): undefined reference to `AuthStatus::staticMetaObject'

https://redd.it/1cuu0l3
@qt_reddit
Is there a better way to insert units in my form?

I wonder if there is a better way to insert the unit of my form while someone is entering a number.

TBH if I would know how to do this I would allow the user to enter its Value in inch as well as in mm.

I have no clue how this is done 'the Qt way'


Thanks in advance for any hint.

TextField{
id: innerDia
text: ""
placeholderText: "Innendurchmesser in mm"
onTextChanged: {
if (!innerDia.text.endsWith("mm"))
innerDia.text = innerDia.text + " mm"
// place curser before "mm"
innerDia.cursorPosition = innerDia.text.length - 3
}
}

https://redd.it/1cuw0d6
@qt_reddit
Dynamic QML component

It is better use C++ for dynamic QML component or Javascript Dynamic QML compinent.

In C++:
Q_INVOKABLE void createComponent(const QString &qmlCode, QObject *parent = nullptr);

In Javascript:
const newObject = Qt.createQmlObject('some string');

Which is better and why ?
I feel easier in JS, but I want to utilize C++, I want experts suggestion on which one to take when and why.

https://redd.it/1cvgnfk
@qt_reddit
Why their are less tutorials around qt or qt-qml?

I want to develop some software for realtime data, but I could not find any good resources and guide for qt. I want to create prototype projects with qt and map where rider location is realtime track by desktop app. But issue is the I could not find the resources. I find few examples code by qt and documentation around it but not a comprehensive tutorial around?

https://redd.it/1cvk94n
@qt_reddit
Qt Zipfiles

I am new to Qt and have a project that needs to be migrated to Qt 6. In our project, we normally use QuaZip, but I think we need to switch to QZipReader and QZipWriter from the Qt framework. Will this migration be straightforward? Are there any functionalities in QuaZip that QZipReader and QZipWriter do not support?

https://redd.it/1cvuikk
@qt_reddit
Help identifying a crash

Hi,

I am debugging a crash, which I cannot understand. The way I can reproduce this is:
        QString l = "\r";
QChar c = l[0];


This crashes inside the operator, relevant code from 6.7.1:
const QChar QString::operator[](qsizetype i) const
{
verify(i, 1); // this one fails me
return QChar(d.data()[i]);
}

Q_ALWAYS_INLINE constexpr void verify([[maybe_unused]] qsizetype pos = 0,
[[maybe_unused]] qsizetype n = 1) const
{
Q_ASSERT(pos >= 0);
Q_ASSERT(pos <= d.size);
Q_ASSERT(n >= 0);
Q_ASSERT(n <= d.size - pos); // here d.size is 0!!!11
}


Code does work if I change l = "1". What am I missing here?

https://redd.it/1cvzh7c
@qt_reddit
Cahier - Advanced note-taking with bibliography management (v0.5.0 release)

Hello!

Cahier is the app that I've been developing for a year and a half, written using Qt. It is a knowledge base created to support out of the box the research workflow. It allows you to both store and read study documents (PDFs, web pages, etc.), extract and link highlights from those documents, and produce written content based on them.

It's a local-first, native application for Windows and macOS.

v0.5.0 introduces better support for highlight links. Notes can be linked to highlights using cards. The startup speed is better. We've recently also added Markdown export in notes and improved the design of macOS apps.

For a more comprehensive list of changes, check our Twitter. Download the software here.

https://redd.it/1cweg8b
@qt_reddit
How can I integrated a Qml project to Android studio project

I have a qt quick project management by Qt creator. It can direct building to a apk. But I have seen someone
Use android java code to start a qt quick project.How to do that? Someone tell more information, thanks a lot !

https://redd.it/1cwfkfl
@qt_reddit
Adobe Illustrator like Pen Tool on a QGraphicsScene

Thought I'd come on here and ask this:

How would I create an Adobe Illustrator like pen tool for my QGraphicsScene? (e.g. click point by point to define the geometry and click and drag to draw curves)

I am familiar with QPainterPath and it's respective methods, but I came here to ask how the hell I would achieve this. Any help is appreciated.

https://redd.it/1cwj1im
@qt_reddit