Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.4k Topics 456.4k Posts
  • How to include shared library?

    Unsolved
    3
    0 Votes
    3 Posts
    1k Views
    mrdebugM
    On Linux try to use unix:!mac { LIBS += -Wl,-rpath=\$$ORIGIN/libs } makes portable your application
  • QCamera/QCameraFocus Windows 10 tablet

    Solved
    6
    0 Votes
    6 Posts
    624 Views
    A
    @SGaist I don't know exactly. It's a 5Mpixels USB camera mounted on rear of an industrial tablet.
  • How to save a region of interest on a QGraphicsScene

    Solved
    13
    0 Votes
    13 Posts
    2k Views
    BallasB
    Hi all Thanks for all the support and suggestions. I have a better solution and I am posting it here for your review. Please let me know if you find any other improvements that can be made. #include <QGraphicsScene> #include <QGraphicsView> #include <QWidget> #include <QImage> #include <QGraphicsSceneMouseEvent> #include <QVBoxLayout> #include <QGraphicsPixmapItem> #include <QGraphicsRectItem> #include <opencv2/opencv.hpp> #include <opencv2/imgproc.hpp> class OverlayRectangle : public QGraphicsItem { public: enum { Type = UserType + 1026 }; OverlayRectangle(const QRectF &, cv::Mat &, QGraphicsItem *parent = 0); QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; int type() const override; protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; private: QRectF rectShape; QSizeF dragDelta; bool resizeShape; cv::Mat & overlayImage; }; class ImageViewer : public QWidget { Q_OBJECT public: explicit ImageViewer(QWidget *parent = nullptr); void setImage(const QString & fileName); void addOverlay(QRectF rect); private: QGraphicsScene *imageScene; QGraphicsView *imageView; QGraphicsPixmapItem *imagePixmap; cv::Mat cvImage; }; #include "image_viewer.h" #include "cvmatandqimage.h" #include <QDebug> OverlayRectangle::OverlayRectangle(const QRectF & cvRect, cv::Mat & overlayImg, QGraphicsItem *parent) : QGraphicsItem(parent), rectShape(cvRect), overlayImage(overlayImg) { setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); resizeShape = false; } QRectF OverlayRectangle::boundingRect() const { return rectShape; } void OverlayRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); try { QRectF rect0 = mapRectToScene(boundingRect()); cv::Rect2d cvRect0(rect0.x(), rect0.y(), rect0.width(), rect0.height()); cv::Mat croppedImage = overlayImage(cvRect0); cv::cvtColor(croppedImage, croppedImage, cv::COLOR_BGR2GRAY); cv::GaussianBlur(croppedImage, croppedImage, cv::Size(51, 51), 51, 51); QImage processedImage = QtOcv::mat2Image(croppedImage); painter->drawImage(rectShape, processedImage); } catch (...) { return; } QPen blackPen(Qt::blue); blackPen.setWidth(2); painter->setPen(blackPen); painter->drawRect(rectShape); QRectF brRect(rectShape.x() + rectShape.width() - 20, rectShape.y() + rectShape.height() - 20, 20, 20); painter->drawRect(brRect); } int OverlayRectangle::type() const { return Type;} void OverlayRectangle::mousePressEvent(QGraphicsSceneMouseEvent *event) { auto currentPos0 = event->scenePos(); QPointF dragRectBR = mapToScene(boundingRect().bottomRight()); QRectF dragRect(dragRectBR.x() - 20, dragRectBR.y() - 20, 20, 20); if(dragRect.contains(currentPos0)) { dragDelta.setWidth(dragRectBR.x() - currentPos0.x()); dragDelta.setHeight(dragRectBR.y() - currentPos0.y()); resizeShape = true; } QGraphicsItem::mousePressEvent(event); } void OverlayRectangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { auto currentPos0 = event->scenePos(); auto sceneRectTL0 = mapToScene(boundingRect().topLeft()); if(resizeShape == true) { auto newWidth = currentPos0.x() - sceneRectTL0.x() + dragDelta.height(); auto newHeight = currentPos0.y() - sceneRectTL0.y() + dragDelta.height(); if( newWidth > 50 && newHeight > 50 ) { prepareGeometryChange(); rectShape.setWidth(newWidth); rectShape.setHeight(newHeight); update(); } return; } QGraphicsItem::mouseMoveEvent(event); } void OverlayRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { resizeShape = false; QGraphicsItem::mouseReleaseEvent(event); } ImageViewer::ImageViewer(QWidget *parent) : QWidget(parent) { imageScene = new QGraphicsScene(this); imageView = new QGraphicsView(imageScene); imagePixmap = nullptr; QVBoxLayout *topLayout = new QVBoxLayout; topLayout->addWidget(imageView); setLayout(topLayout); imageView->setDragMode(QGraphicsView::NoDrag); } void ImageViewer::setImage(const QString & fileName) { QImage image(fileName); if(imagePixmap != nullptr) { imageScene->removeItem(imagePixmap); delete imagePixmap; } imagePixmap = new QGraphicsPixmapItem(QPixmap::fromImage(image)); imageView->setSceneRect(0, 0, image.width(), image.height()); imageScene->addItem(imagePixmap); cvImage = cv::imread(fileName.toStdString().c_str()); } void ImageViewer::addOverlay(QRectF cvRect) { auto overlayRect = new OverlayRectangle(cvRect, cvImage); imageScene->addItem(overlayRect); }
  • Audio Playback issues with various formats (m4a, mp3, wav)

    Unsolved qtmultimedia
    2
    0 Votes
    2 Posts
    1k Views
    A
    Any updates or workarounds here?
  • Windows scaling settings are ignored for part of the apps widgets

    Solved
    1
    0 Votes
    1 Posts
    164 Views
    No one has replied
  • Access from Child in another CPP Class

    Solved
    10
    0 Votes
    10 Posts
    390 Views
    jsulmJ
    @Stevendragoes Looks good
  • Compare QVariable with Enum of DLL

    Solved
    3
    0 Votes
    3 Posts
    356 Views
    H
    @Christian-Ehrlicher thanks for your answer. If found a second solution here But to begin I had to add: qRegisterMetaTypeCCS::DataManagerState("state"); Now it works.
  • QSpinbox editingFInished signal on up/down arrow press

    Solved
    9
    0 Votes
    9 Posts
    3k Views
    S
    @jsulm Yes...it's perfect..Thanks
  • Cant use my program when "special chars" are in name.

    Solved
    14
    0 Votes
    14 Posts
    966 Views
    aha_1980A
    Hi @BD9a, then please mark this topic as SOLVED. Thanks.
  • This topic is deleted!

    Unsolved
    3
    0 Votes
    3 Posts
    972 Views
  • Lrelease and type="unfinished"

    Moved Solved
    9
    0 Votes
    9 Posts
    3k Views
    Christian EhrlicherC
    Then please mark the topic as solved, thx.
  • How to place cursor at the beginning of a cell of QTableWIdget

    Unsolved
    4
    0 Votes
    4 Posts
    548 Views
    SGaistS
    That's not the answer to my question. Again: why is that code using cell widgets ? What for ?
  • I can't set layout position

    Unsolved
    10
    0 Votes
    10 Posts
    3k Views
    SGaistS
    Please take the time to learn about the use of layouts.
  • MouseButtonRelease does not work on Linux after populating the combo box

    Unsolved
    9
    0 Votes
    9 Posts
    679 Views
    L
    Thank you. think I have it working now.
  • Control general audio mixer

    Solved
    3
    0 Votes
    3 Posts
    311 Views
    D
    This is why it was so difficult to find this out from the Qt doc. Thanks
  • How to stop screen reader(Narrator) from reading password field in QML

    Locked Unsolved
    2
    0 Votes
    2 Posts
    174 Views
    SGaistS
    Hi, Please don't post the exact same question in multiple sub-forum. One is enough. In case you're on the wrong one, you can ask a moderator to move it. Closing this one as duplicate.
  • Stick a widget to the mouse while Drag N Drop?

    Solved
    6
    0 Votes
    6 Posts
    1k Views
    Pl45m4P
    @m1212e said in Stick a widget to the mouse?: but I couldn't really understand what I have to do The code sample posted by the OP shows a section from a version control system (like Git) change log file. The + (green background) lines indicate insertions. So, if you know what to look for, it takes 3 seconds, until you know what's going on there :-) In case you didnt know that :-)
  • Get dates between two end dates

    Solved qdatetime qt5 desktop
    6
    0 Votes
    6 Posts
    1k Views
    A
    @J-Hilk @aha_1980 I think i failed to see simplicity of this one. thank you for guidence.
  • Modbus RTU client: send failed error

    Unsolved
    1
    0 Votes
    1 Posts
    325 Views
    No one has replied
  • How to get length of QByteArray with binary data?

    Unsolved
    2
    0 Votes
    2 Posts
    238 Views
    jsulmJ
    @Infinity https://doc.qt.io/qt-5/qbytearray.html#length