Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.3k Topics 456.1k Posts
  • QGraphicsItem resize with keeping aspect ratio

    Solved
    6
    0 Votes
    6 Posts
    922 Views
    A
    I found a solution using vector math.(thanks to my colleague Dima Chernikov) ABCD - our picture. K' - cursor point. D2 - the point we are looking for(new position of D) gif example: https://media.giphy.com/media/uffXKjNNy5ykzpvsR2/giphy.gif (circlePos_ == eBottomLeft) in code [image: d835c77d-c279-4bed-8ff5-7fc321c38062.jpg] code: (I will most likely redo it later using templates. but now it is more clear for understanding) void MovableCircle::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { auto pos = mapToScene(event->pos() + _shiftMouseCoords); qreal xl = pos.x(); qreal yl = pos.y(); auto rect = parentItem()->boundingRect(); QPointF a(rect.x(), rect.y()); QPointF b(rect.x() + rect.width(), rect.y()); QPointF c(rect.x() + rect.width(), rect.y() + rect.height()); QPointF d(rect.x(), rect.y() + rect.height()); if (circlePos_ == eTopRight) { Vec2d dc(c.x()-d.x(), c.y()-d.y()); Vec2d cb(b.x()-c.x(), b.y()-c.y()); Vec2d db(b.x()-d.x(), b.y()-d.y()); Vec2d dk(pos.x()-d.x(), pos.y()-d.y()); auto dc_len = dc.length(); auto cb_len = cb.length(); auto db_len = db.length(); auto dk_len = dk.length(); auto dkdb_dot = Vec2d<qreal>::dot(db, dk); auto cos_kdb = dkdb_dot/(db_len*dk_len); auto dd2_len = dk_len * cos_kdb; auto x =(dd2_len * dc_len) / (std::sqrt(cb_len * cb_len + dc_len * dc_len)); auto y = std::sqrt(dd2_len * dd2_len - x * x); if (x < 10 || y < 10) return; pos.setX(d.x()+x); pos.setY(d.y()-y); } if (circlePos_ == eBottomRight) { Vec2d ad(d.x()-a.x(), d.y()-a.y()); Vec2d dc(c.x()-d.x(), c.y()-d.y()); Vec2d ac(c.x()-a.x(), c.y()-a.y()); Vec2d ak(pos.x()-a.x(), pos.y()-a.y()); auto ad_len = ad.length(); auto dc_len = dc.length(); auto ac_len = ac.length(); auto ak_len = ak.length(); auto akac_dot = Vec2d<qreal>::dot(ac, ak); auto cos_kac = akac_dot/(ac_len*ak_len); auto ad2_len = ak_len * cos_kac; auto x =(ad2_len * dc_len) / (std::sqrt(ad_len * ad_len + dc_len * dc_len)); auto y = std::sqrt(ad2_len * ad2_len - x * x); if (x < 10 || y < 10) return; pos.setX(a.x()+x); pos.setY(a.y()+y); } if (circlePos_ == eTopLeft) { qDebug()<<this->parentItem()->boundingRect(); Vec2d cb(b.x()-c.x(), b.y()-c.y()); Vec2d ba(a.x()-b.x(), a.y()-b.y()); Vec2d ca(a.x()-c.x(), a.y()-c.y()); Vec2d ck(pos.x()-c.x(), pos.y()-c.y()); auto cb_len = cb.length(); auto ba_len = ba.length(); auto ca_len = ca.length(); auto ck_len = ck.length(); auto ckca_dot = Vec2d<qreal>::dot(ca, ck); auto cos_kca = ckca_dot/(ca_len*ck_len); auto cd2_len = ck_len * cos_kca; auto y =(cd2_len * cb_len) / (std::sqrt(ba_len * ba_len + cb_len * cb_len)); auto x = std::sqrt(cd2_len * cd2_len - y * y); if (x < 10 || y < 10) return; pos.setX(c.x()-x); pos.setY(c.y()-y); } if (circlePos_ == eBottomLeft) { qDebug()<<this->parentItem()->boundingRect(); Vec2d ba(a.x()-b.x(), a.y()-b.y()); Vec2d ad(d.x()-a.x(), d.y()-a.y()); Vec2d bd(d.x()-b.x(), d.y()-b.y()); Vec2d bk(pos.x()-b.x(), pos.y()-b.y()); auto ba_len = ba.length(); auto ad_len = ad.length(); auto bd_len = bd.length(); auto bk_len = bk.length(); auto bkbd_dot = Vec2d<qreal>::dot(bd, bk); auto cos_kdb = bkbd_dot/(bd_len*bk_len); auto bd2_len = bk_len * cos_kdb; auto x =(bd2_len * ba_len) / (std::sqrt(ad_len * ad_len + ba_len * ba_len)); auto y = std::sqrt(bd2_len * bd2_len - x * x); if (x < 10 || y < 10) return; pos.setX(b.x()-x); pos.setY(b.y()+y); } setPos(pos); emit circleMoved(); }
  • printing lines in PDF qt

    Unsolved
    4
    0 Votes
    4 Posts
    346 Views
    D
    I want to draw lines of a Table. I can write text inside the custom created table inside PDF. but drawLine of QPainter is not working. here is my sample code: QPdfWriter writer(filename); writer.setPageSize(QPagedPaintDevice::A4); writer.setPageMargins(QMargins(30, 30, 30, 30)); QPainter painter(&writer); painter.setPen(Qt::black); painter.setFont(QFont("Times", 10)); QRect r = painter.viewport(); QString citydate = "City, "; citydate += currDate(); painter.drawText(r, Qt::AlignRight, citydate); QString sender = "COMPANY XYZ\n"; sender += "Random Street 12/314A\n"; sender += "123-1232 City\n"; painter.drawText(r, Qt::AlignLeft, sender); painter.drawLine(20, 20, 100, 100); painter.end(); I Want to have like: | | | without gaps.....straight lines... both Horizontal and Vertical lines
  • QMenu using a lot of memory

    Solved qmen contex menu memory memory leak
    5
    0 Votes
    5 Posts
    1k Views
    nageshN
    @Roysten-Rigobert Why don't you create menu/actions at once by making menu as member variable? and in contextMenu(QPoint) slot call only the menu->exec(mapToGlobal(pos));
  • X11 connection broken when using Qt 5.14

    Solved
    7
    0 Votes
    7 Posts
    9k Views
    Kent-DorfmanK
    @artwaw ** @Kent-Dorfman xming is not outdated, it's just no longer free http://www.straightrunning.com/XmingNotes/ but actively developed. It's just OP using very outdated one. ed text** The "free version" the op uses is outdated. hasn't been updated in like 6 or 7 years.
  • SIGNALS not being called when triggered.

    Unsolved
    14
    0 Votes
    14 Posts
    766 Views
    C
    I created a very small server and so far it has worked just fine, I didn't change the QTcpSocket / the client code at all. I am going to slowly work my way back up and let you know how it goes. server.h #ifndef SERVER_H #define SERVER_H #include <QTcpSocket> #include <QTcpServer> class Server : public QTcpServer { public: Server(); void reading(); QTcpSocket* client; }; #endif // SERVER_H server.cpp #include "server.h" Server::Server() { qDebug() << "Server is creating conections"; connect(this, &QTcpServer::newConnection, this, [=](){ client = this->nextPendingConnection(); connect(client, &QTcpSocket::readyRead, this, &Server::reading); client->write("Hello, World!"); client->flush(); }); } void Server::reading(){ qDebug() << "Reading from the client: " << client->readAll(); } Client output (Based off of the code in my previous posts) QAbstractSocket::HostLookupState QAbstractSocket::ConnectingState QAbstractSocket::ConnectedState WRITEING CONNECTED READING DATA Hello, World! Server output Server is creating conections Reading from the client: "HELLO, WE HAVE SUCCESSFULLY CONNECTED"
  • Creating new QObject runs in wrong thread

    Unsolved
    10
    0 Votes
    10 Posts
    577 Views
    nageshN
    @ocgltd I suggest to read about thread affinity in qt doc https://doc.qt.io/qt-5/qobject.html#thread-affinity
  • Trying to add qlayout ... which allready has a layout.

    Solved
    4
    0 Votes
    4 Posts
    370 Views
    SGaistS
    Use the doc Luke ;-)
  • Triggering action by click ouside a widget

    Solved
    3
    0 Votes
    3 Posts
    263 Views
    B
    Thank you very munch. As a beginner with Qt I always forget that you have to forward the unhandled events.
  • qmake: copy dir or file on each build

    Unsolved
    3
    0 Votes
    3 Posts
    641 Views
    M
    It looks like QMAKE_POST_LINK is not suitable for this, as its no executed on each build is there another solution like "INSTALLS" qmake variable?
  • Too long to load data from Sql Server

    Unsolved
    23
    0 Votes
    23 Posts
    2k Views
    JonBJ
    @Duy-Khang How does the video clarify anything? Do you think we do not understand what you have asked so far? How would you like someone to help you when we don't know why it doesn't work for you? Best of luck....
  • This topic is deleted!

    Unsolved
    2
    0 Votes
    2 Posts
    39 Views
  • The program has unexpectedly finished

    Unsolved qt5 charts
    8
    0 Votes
    8 Posts
    1k Views
    D
    @Pl45m4 thank you
  • QDesktopServices::open - kf.windowsystem: Could not find any platform plugin

    Solved
    3
    0 Votes
    3 Posts
    2k Views
    R
    the touble is in option Project -> Run -> [x] Add build library search path to LD_LIBRARY_PATH if uncheck it, all works fine under QtCreator, and problem is gone
  • How to cross-compile QT App on RPi3

    Unsolved
    8
    0 Votes
    8 Posts
    583 Views
    KroMignonK
    @dziko147 said in How to cross-compile QT App on RPi3: I would like to use the kernel image generated by buildroot not Raspbian distribution What did you add to your custom buildroot image? You must, at least, have add QT5 support.
  • 0 Votes
    14 Posts
    1k Views
    B
    @jsulm @Christian-Ehrlicher Thx. Issue solved. Everything works fine for me now. Example published here
  • This topic is deleted!

    Unsolved
    14
    0 Votes
    14 Posts
    73 Views
  • Timer blocking applications - reactivation

    Solved
    4
    0 Votes
    4 Posts
    455 Views
    VRoninV
    Threads are a minefield. For example, in your code if this gets deleted before the other thread finishes your program would crash
  • Connection QT and NCReport

    Unsolved
    3
    0 Votes
    3 Posts
    332 Views
    O
    @jsulm thank you
  • Getting - Controller Error: QLowEnergyController::ConectionError

    Unsolved
    6
    0 Votes
    6 Posts
    970 Views
    Pl45m4P
    @sarthak031 You are using this example (https://github.com/Gawhary/BLE-Tester), aren't you? Where exactly the error occurs (use debugger)? Is your device BLE ready? Test your connection using the official BTLE examples https://doc.qt.io/qt-5/qtbluetooth-le-overview.html#using-qt-bluetooth-low-energy-api https://doc.qt.io/qt-5/qtbluetooth-lowenergyscanner-example.html
  • Updated Qt Creator - "Plugin Loader Messages" at startup

    Unsolved
    1
    0 Votes
    1 Posts
    155 Views
    No one has replied