Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.5k Topics 457.3k Posts
  • A continuous capture of a window sceen as QPixmap? for OpenCV

    Solved
    7
    0 Votes
    7 Posts
    479 Views
    J
    The trick is to get targetWindowId and feed that to QScreen grabWindow. This will give you QPixmap format which is easily converted into OpenCV cv::Mat. For that I picked a class which is called private in Qt source code because it is not part of their API. class QCapturableWindowPrivate : public QSharedData { public: using Id = size_t; QString description; Id id = 0; static const QCapturableWindowPrivate *handle(const QCapturableWindow &window) { return window.d.get(); } QCapturableWindow create() { return QCapturableWindow(this); } }; class Screenshot { public: Screenshot(const QString& windowName); void displayLiveView(); private: QPixmap grabWindow(); WId targetWindowId = 0; QWindowCapture windowCapture; }; Screenshot::Screenshot(const QString& windowName) { WindowListModel windowListModel; windowListModel.populate(); QCapturableWindow targetWindow; // Window we are looking for bool windowFound = false; for (int i = 0; i < windowListModel.rowCount(); i++) { QModelIndex index = windowListModel.index(i); if (index.isValid()) { QString currentWindowDesc = windowListModel.data(index, Qt::DisplayRole).toString(); if (currentWindowDesc.contains(windowName)) { targetWindow = windowListModel.window(index); windowFound = true; break; } } } if (!windowFound) { qDebug() << "Window not found!"; return; } windowCapture.setWindow(targetWindow); auto handle = QCapturableWindowPrivate::handle(targetWindow); targetWindowId = handle ? handle->id : 0; } QPixmap Screenshot::grabWindow() { if (targetWindowId == 0) return QPixmap(); QScreen *screen = QGuiApplication::primaryScreen(); if (!screen) return QPixmap(); return screen->grabWindow(targetWindowId); } void Screenshot::displayLiveView() { while (true) { QPixmap pixmap = grabWindow(); if (pixmap.isNull()) { qDebug() << "Failed to capture the window."; continue; } QImage image = pixmap.toImage(); cv::Mat mat(image.height(), image.width(), CV_8UC4, (void*)image.constBits(), image.bytesPerLine()); cv::imshow("Live View", mat); if (cv::waitKey(30) == 27) { break; } } } int main(int argc, char *argv[]) { QApplication app(argc, argv); // Print available windows WindowListModel model; for (int i = 0; i < model.rowCount(); i++) { QModelIndex index = model.index(i); if (index.isValid()) { QString windowDesc = model.data(index, Qt::DisplayRole).toString(); std::cout << i + 1 << ". " << windowDesc.toStdString() << std::endl; } } Screenshot screenshot("Settings"); //The name of the window from the printed list screenshot.displayLiveView(); return 0; }
  • Different coordinates after setGeometry applied to QGraphicsView

    Unsolved
    5
    0 Votes
    5 Posts
    427 Views
    D
    @KenAppleby-0 Thank you. Now I am trying to understand why every app adapt dpi differently, Gimp, Firefox and Qt.
  • Working with Graphics View Framework and QSvgItem

    Solved
    2
    0 Votes
    2 Posts
    182 Views
    C
    So I asked chat GPT and it gave some suggestion that seem to work: void centerSVGItem() { QRectF transformedBoundingRect = svgItem->sceneTransform().mapRect(svgItem->boundingRect()); QPointF svgCenter = transformedBoundingRect.center(); QPointF sceneCenter = scene->sceneRect().center(); QPointF offset = sceneCenter - svgCenter; svgItem->setPos(svgItem->pos() + offset); }; //... QObject::connect(action1, &QAction::triggered, [&]() { QRectF transformedBoundingRect = svgItem->sceneTransform().mapRect(svgItem->boundingRect()); svgItem->setTransformOriginPoint(transformedBoundingRect.center()); svgItem->setRotation(rotation += 45); centerSVGItem(); scene->update(); }); [image: 62459644-d48c-4a14-9c20-0e95e1b6d73d.gif] If you have any other suggestions or ideas please feel free to comment.
  • Qt6 platform rendering issues on Ubuntu 22.04

    Unsolved
    31
    0 Votes
    31 Posts
    8k Views
    R
    The default application palette seems to be broken in places with Qt 6.5 and higher. As a workaround, I serialized the working palette into a file using the testlabel app, compiling it with Qt 6.4.3. Then I added the resulting binary file to my application resources. When compiling it with a higher Qt version, I merely overwrite the default palette into the app instance. Seems to work OK; now at least I can do some more serious testing.
  • QDoc is not generating output for \property and \enum

    Unsolved
    1
    0 Votes
    1 Posts
    154 Views
    No one has replied
  • 0 Votes
    35 Posts
    4k Views
    JonBJ
    @saerpa I respect what you have chosen to do, maybe there is a difference in MinGW compiler or even in Qt. However, are you aware that Qt 5.9 is really old now? It may have issues which have been resolved. I leave you with the thought that it might be better to move to a newer version, assuming one of those does work correctly with MinGW 32-bit.
  • How to read data in questDB with QT application?

    Unsolved
    9
    0 Votes
    9 Posts
    952 Views
    JianJianJ
    @newKid can you show the code how to made it, i have the same condition, use quesdb in qt application,tks
  • get milliseconds from QTimeEdit

    Solved
    7
    0 Votes
    7 Posts
    1k Views
    E
    Hi Chris, maybe I'm completely wrong. I think my problem is a different one. I grab the time value in a keyPressEvent loop. SO you enter the last number and press then Enter or Return. But the QTimeEdit didn't recognize the last entered number yet. if(event->key() == Qt::Key_Return|| event->key() == Qt::Key_Enter||event->key() == Qt::Key_Tab) { ... } If I put in if(event->key() == Qt::Key_Return|| event->key() == Qt::Key_Enter||event->key() == Qt::Key_Tab) { QTimeEdit::keyPressEvent(event); ... } I get the correct results. Thanks for your support. Without, I couldn't figure out my mistake.
  • After upgrading to Win11, compiling project is failed.

    Solved
    3
    0 Votes
    3 Posts
    269 Views
    W
    @Christian-Ehrlicher Thank you for your reply. After trying, this issue is solved. Have a nice day.
  • Qt5Test.dll error After Deployment of OpenCV application

    Unsolved
    4
    0 Votes
    4 Posts
    420 Views
    Christian EhrlicherC
    If you would not use anything from QTest library then windows would not ask for it. Maybe look with Dependency Walker to see where it comes from.
  • 0 Votes
    9 Posts
    556 Views
    Christian EhrlicherC
    @Crag_Hack Yes
  • Resizing QLineEdit in a QGridLayout

    Solved
    18
    0 Votes
    18 Posts
    4k Views
    S
    After some experimentation, I've finally got the "ideal" solution: If you want to use colspan and rowspan in the same way I'm looking for, then every row and column that is stretched through must have a stretch set to 1. Final code: QWidget *widget = new QWidget; setCentralWidget(widget); QLineEdit *edit = new QLineEdit("Test"); QLineEdit *edit2 = new QLineEdit("Test2"); QLineEdit *edit3 = new QLineEdit("Test3"); QLineEdit *edit4 = new QLineEdit("Test4"); QGridLayout *layout = new QGridLayout(widget); layout->setColumnStretch(0, 1); layout->setColumnStretch(1, 1); layout->setColumnStretch(2, 1); layout->setRowStretch(0, 1); layout->setRowStretch(1, 1); layout->setRowStretch(2, 1); layout->addWidget(edit, 0, 0, 2, 2); layout->addWidget(edit2, 0, 2, 1, 1); layout->addWidget(edit3, 2, 0, 1, 1); layout->addWidget(edit4, 2, 1, 1, 2); edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); edit2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); edit3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); edit4->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); Results in: [image: 5bff5352-35d9-4832-bb3e-d1d1e3213f9a.png] Before I had assumed that the default stretch of every widget in a layout was 1, but nope. This, however, fixes it. Also ensure that every column and row that is spanned at all is stretched (i.e. column 0 with span 2 = 0 and 1 need to be stretched to 1).
  • CDialog::Create failing.

    Solved
    2
    0 Votes
    2 Posts
    241 Views
    PerdrixP
    Changing the dialogue definition changing WS_CHILD to WS_POPUP appears to fix it. IDD_PROCESSING DIALOGEX 0, 0, 438, 332 STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_POPUP FONT 8, "MS Shell Dlg", 0, 0, 0x0 BEGIN CONTROL "",IDC_PICTURE,"Static",SS_BLACKFRAME | SS_SUNKEN,6,28,427,148 LTEXT "Histo",IDC_ORIGINAL_HISTOGRAM,177,186,256,140,SS_SUNKEN LTEXT "Settings",IDC_SETTINGS,6,189,167,137,NOT WS_VISIBLE,WS_EX_STATICEDGE LTEXT "",IDC_INFO,6,6,427,16,0,WS_EX_TRANSPARENT CONTROL "",IDC_PROCESSING_PROGRESS,"msctls_progress32",PBS_SMOOTH,6,176,427,4 END David
  • Why does ${Qt6Core_INCLUDE_DIRS} contain Qt6::ZlibPrivate?

    Unsolved
    2
    0 Votes
    2 Posts
    626 Views
    C
    @Gertio said in Why does ${Qt6Core_INCLUDE_DIRS} contain Qt6::ZlibPrivate?: the following CMake minimal example configuration fails: Where did this come from? What are you trying to build? Why does ${Qt6Core_INCLUDE_DIRS} contain Qt6::ZlibPrivate? Qt6, by default, is built with a private copy of Zlib and some other libraries.
  • QMediaRecorder::record() delay on Windows

    Unsolved multimedia recording audio qmediarecorder
    11
    0 Votes
    11 Posts
    2k Views
    S
    @SGaist That is correct. The same application tested on different Windows machines presents exactly the same behavior.
  • How to Set the Hiding and Displaying of QScrollBar through QSS Statements

    Solved
    4
    0 Votes
    4 Posts
    361 Views
    X
    @Axel-Spoerl Thank you first! I use QScrollBar in QScrollArea. I think it is difficult to get capture the mouse leave or enter enevt in this case.
  • Load internet image into QWidget...

    Unsolved
    2
    0 Votes
    2 Posts
    241 Views
    sierdzioS
    @1XU7 said in Load internet image into QWidget...: I'm using QFrame to store image via stylesheet. Why? Just use QLabel, you can set it to display image instead of text with this property: https://doc.qt.io/qt-6/qlabel.html#pixmap-prop Image can come from the network, sure, you'll just need to download it.
  • This topic is deleted!

    Unsolved
    5
    0 Votes
    5 Posts
    112 Views
  • Problems using QUdpSocket

    Unsolved
    2
    0 Votes
    2 Posts
    123 Views
    Christian EhrlicherC
    Please provide some code on what you are doing. Also note that there is an example on how to use the QUdpSocket in the documentation which you should try out.
  • How to create rounded corners for GIF images.

    Unsolved
    6
    0 Votes
    6 Posts
    894 Views
    Q
    @Pl45m4 Thanks for your reply! I found that if it was a GIF, I would also need to rewrite the paintEvent function to draw each frame in the same way I did earlier.