Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.5k Topics 457.0k Posts
  • How to fix strected image label in a layout?

    Unsolved
    8
    0 Votes
    8 Posts
    780 Views
    B
    @Rangerguy128 Yes, as @JonB replied above (also need to write codes). But I don't see that makes any sense. When you change scaledcontents to false, it won't keep the image size when it is true, it just show the actual size. So if you are not going to keep the image in its actual size, you need to write codes as @mpergand shows you.
  • 0 Votes
    3 Posts
    404 Views
    J
    @Pl45m4 only one thing: which project type should I create in Visual Studio? Qt Designer custom widget? do we need to export the widget? __declspec(dllexport)?? The only problem is the examples are for use in Qt Creator I think while I am in Visual Studio... is there a VS example? How can I find the value of the macros like $$[QT_INSTALL_PLUGINS] and ${INSTALL_EXAMPLEDIR}?
  • Creating a new widget class over using a stackedWidget?

    Solved
    2
    0 Votes
    2 Posts
    226 Views
    Pl45m4P
    @he_R0 Hi and welcome :) should I always be using a StackedWidget, or are there cases where creating a new designer form class is better? As often: it depends... Do you want to have your widgets at the same place and showing only one at a time or do you want them to be next to each other (or in a new window) and showing/using multiple at once? A QStackedWidget is one of Qt's plenty container widgets... there are also widgets like QTabWidget or different Model/Views. QStackedWidget works like a book with pages... you can flip the pages in-place, but you can only see the currentWidget. I didn't want to make it messy and have too many stackedWidgets embedded into each other Multiple or cascading QStackedWidgets?! Mh, that already sounds like bad design. Can't see why you need to do this, since you can simply add a new widget to the only QStackedWidget. There is no need to embed a new QStackedWidget and fill it with content widgets... there might be some edge cases, where it could be viable, but I can't see a reason why you need to do this right now ;-) Since we know nothing about your app, you should develop a feeling for which design suits your app the best. Is it more technical? like some simple inputs/outputs, controls and some processing going on in the background. Or do you have some fancy, modern app in mind, with lots of toolbars, side widgets, menus etc.? using QT for a personal project. Because of this, you are not limited and you can try out few things... if you have a more concrete sketch of your app feel free to ask again :) Happy coding :)
  • QPainter does not work

    Unsolved qpainter qline qimage qwidget qpaintevent
    18
    0 Votes
    18 Posts
    3k Views
    C
    @Joe-von-Habsburg My example recast with a changing background: // widget.h #ifndef WIDGET_H #define WIDGET_H #include <QWidget> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); // QWidget interface protected: void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void paintEvent(QPaintEvent *event); private slots: void setBackground(); private: QImage mBackground; QPointF mFrom; QPointF mTo; }; #endif // WIDGET_H // widget.cpp #include "widget.h" #include <QPaintEvent> #include <QPainter> #include <QLinearGradient> #include <QRandomGenerator> #include <QTimer> #include <QDebug> Widget::Widget(QWidget *parent) : QWidget(parent) , mBackground(500, 500, QImage::Format_RGB32) { setBackground(); QTimer *t = new QTimer(this); connect(t, &QTimer::timeout, this, &Widget::setBackground); t->start(1000); } Widget::~Widget() { } void Widget::mousePressEvent(QMouseEvent *event) { mFrom = event->position(); mTo = mFrom; } void Widget::mouseReleaseEvent(QMouseEvent *event) { mTo = event->position(); update(); } void Widget::paintEvent(QPaintEvent *event) { QPainter p(this); p.drawImage(event->rect(), mBackground); if (mFrom != mTo) { QPen pen(Qt::red); pen.setWidth(3); p.setPen(pen); p.drawLine(mFrom, mTo); } p.end(); } void Widget::setBackground() { QPainter p(&mBackground); const QRectF rectf(mBackground.rect()); QLinearGradient grad(rectf.topLeft(), rectf.bottomRight()); grad.setColorAt(0, QColor::fromRgb(QRandomGenerator::global()->generate())); grad.setColorAt(1, QColor::fromRgb(QRandomGenerator::global()->generate())); p.fillRect(mBackground.rect(), QBrush(grad)); p.end(); update(); }
  • bpftrace and printing content of QString

    Unsolved
    2
    0 Votes
    2 Posts
    163 Views
    SGaistS
    Hi, Did you also contact the bpftrace folks about that request ?
  • This topic is deleted!

    Unsolved
    11
    0 Votes
    11 Posts
    111 Views
  • QWebSocket doesn't detect lost connection?

    Solved
    2
    0 Votes
    2 Posts
    178 Views
    JonBJ
    @ocgltd I would say "Yes" to first question and "No" to second. You might like to look at forum.qt.io/topic/106382/how-to-check-server-life-using-qwebsocket-ping-pong.
  • Desktop-systray example issue on MAC

    Unsolved
    14
    1 Votes
    14 Posts
    2k Views
    A
    @alzix @achak Hello guys! Did you find any solution for this problem? I have met same problem on Qt6.6.2 and MacOS 14.1 Sonoma. When I exit my app from system tray menu (by calling qApp->exit(0)), I must click on main widget or system tray icon to fully exit app. But, when I call qApp->exit(0) from main widget -> app is exiting normally. Also app exits normally by clicking Quit in dock menu or by Ctrl+Q. Same code on Windows works as expected: app exits.
  • issue with QChartView (v.5.15.12)

    Unsolved
    5
    0 Votes
    5 Posts
    651 Views
    JonBJ
    @lano1106 I started to have a go at looking at your question. But there is a distinct lack of a full example so I have no idea about your situation/what you are trying to do. What UI do you have? Where is the chart view? How/why does your chart view receive a resize event? From code, from the user resizing the containing widget? FWIW I just created a QWidget and put a QChartView on it. no viewport()->resize(). When it shows initially I get QChartView: QSize(178, 78) , chart: QRectF(0,0 178x78) viewport: QSize(178, 78) and if a drag-resize the widget I get QChartView: QSize(296, 225) , chart: QRectF(0,0 296x225) viewport: QSize(296, 225) So my viewport is always same as chart view/chart size. I suggest you create and show a minimal example. Btw I do not fully understand all the intricacies of the GraphicView but I would have expected that changing the Scene rect would also modify its viewport size as well. Changing QGraphicsScene size/rect does not modify either QGraphicsView or its viewport, nor should it. Just in case you are doing so, calling QChart::resize() does not affect either QChartView or its viewport.
  • The QOpenGLWidget and QLabel updates frequently, resulting in memory leaks

    Unsolved
    2
    0 Votes
    2 Posts
    138 Views
    Christian EhrlicherC
    @MissingDream Please properly format your code with the code tags ('</>' button) so we can read it.
  • load image report Corrupt JPEG data: premature end of data segment

    Unsolved
    9
    0 Votes
    9 Posts
    2k Views
    C
    @zhouyinlong Intermittent behaviour would have been good to mention in your first post. All your example images show an image corrupted from the same place. If you give Qt the same image data every time then you get the same result every time. If it sometimes works and sometimes does not then you have to consider that the input image is changing (long before any more abstract causes). For example, you are grabbing the image over the network and truncating it accidentally by mishandling the transfer, or you are trampling over a buffer with out-of-bounds memory accesses. We cannot see your actual code or input image.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • 0 Votes
    1 Posts
    143 Views
    No one has replied
  • 0 Votes
    3 Posts
    381 Views
    J
    @Pl45m4 Thanks!
  • 0 Votes
    3 Posts
    601 Views
    J
    @SGaist Thanks!!
  • How to convert .ui to .h?

    Solved c++ qt conversion
    19
    0 Votes
    19 Posts
    3k Views
    JonBJ
    @StudentScripter Yes, you can do that. And it shows you how they implemented stuff.
  • How to use dxflib library?

    Unsolved
    3
    0 Votes
    3 Posts
    608 Views
    B
    @SGaist Thanks for fast reply. I will try. Have a good day.
  • QT Debug information files, where?

    Unsolved
    6
    2 Votes
    6 Posts
    3k Views
    JonBJ
    @pai_daxing There is nothing to elaborate on. As @jsulm wrote at the time Those debug files are only needed to debug Qt itself. You do not need them to build your app in debug mode.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    4 Views
    No one has replied
  • How process remaining events before shutdown

    Solved
    9
    0 Votes
    9 Posts
    591 Views
    JonBJ
    @ocgltd No, it does nothing other than exiting the event loop, and if that is not running I don't know what it does/does nothing.