qt5

How to use a custom Qt type with a QML signal?

浪尽此生 提交于 2019-12-24 02:18:13
问题 I've created a custom type inside my Qt 5.2 qml application class Setting : public QObject { Q_OBJECT Q_PROPERTY(QString key READ key WRITE setKey) Q_PROPERTY(QVariant value READ value WRITE setValue) public: Setting(QObject * parent = 0); QString key() const; void setKey(QString const & key); QVariant value() const; void setValue(QVariant const & value); private: QString m_key; QVariant m_value; }; and registered it in my main function: int main(int argc, char *argv[]) { QApplication app

Detecting Qt5 with CMake

前提是你 提交于 2019-12-24 01:49:20
问题 I am trying to install and use Qt 5 on Ubuntu. Running CMake for my project which requires Qt 5 leads to: -- The C compiler identification is GNU 4.8.4 -- The CXX compiler identification is GNU 4.8.4 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ --

Cross compiling Qt 5

谁都会走 提交于 2019-12-24 01:41:12
问题 When cross compiling Qt 5.1 (arm-linux-gnueabihf-4.7), what executables are not cross compiled (qmake, moc, bootstrap, etc.)? After reviewing and running the Qt 5 build process, moc and boostrap are getting cross-compiled, which I think is causing a build error... 回答1: When cross compiling Qt 5.1 (arm-linux-gnueabihf-4.7), what executables are not cross compiled (qmake, moc, bootstrap, etc.)? The "host" tools, basically: qmake (qbs in the future) moc uic qdoc rcc 来源: https://stackoverflow.com

How to filter image files from selected directory (which is inside listWidget)

左心房为你撑大大i 提交于 2019-12-24 01:38:08
问题 I have a problem that I don't know how to filter images from a selected directory. I usually use directory.setNameFilters({"*.png", "*.jpg"}); but in this case I can't use that because I need to use the selected directory inside a listWidget . I use signal and slot functions. I mean if I click a directory which is inside a listWidget , the images inside this directory will be displayed in another listWidget . If I click another directory it will do the same function. Please take a look my

How to implement drag-n-dropping widget to another container in qt? [closed]

送分小仙女□ 提交于 2019-12-24 01:24:44
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have a window with several containers. What is the simplest way to implement drag-n-drop between them? 回答1: You have to use a QDrag* object. Then reimplement: virtual void mousePressEvent(QMouseEvent * event); virtual void mouseReleaseEvent(QMouseEvent * event); virtual void mouseMoveEvent(QMouseEvent *event);

How to get length of a song using Qt 5.1?

感情迁移 提交于 2019-12-24 00:52:33
问题 How can I get the length of a song in Qt 5.1 API? I think I can read it using Length metadata but I'm not sure if this metadata will be available for all audio files. 回答1: You seem to be looking for the duration property. This would be the QML solution: duration : int This property holds the duration of the media in milliseconds. If the media doesn't have a fixed duration (a live stream for example) this will be 0. This would be the C++ solution: qint64 QAudioBuffer::duration() const Returns

Generate a SVG file with pyqt5

孤街浪徒 提交于 2019-12-24 00:29:35
问题 I want to use pyqt5 to draw some simple vectorial images using Python. So far, I've managed to generate an image with the following code: import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class MyPainter(QImage): def __init__(self): super().__init__(400, 400, QImage.Format_RGB32) self.fill(Qt.black) painter = QPainter(self) painter.setPen(QPen(Qt.red, 8)) painter.drawRect(40, 40, 200, 100) if __name__ == "__main__": app = QApplication(sys.argv) w =

How to save dynamically generated web page in QWebEngineView?

别说谁变了你拦得住时间么 提交于 2019-12-23 22:27:02
问题 I am loading a web page onto QWebEngineView . A user creates a different kind of tables (reports) and then needs to save those tables to local computer as a web page. Here is what I have tried: Here I use a QWebEnginePage::save() method, but nothing happens: connect(saveButton, &QPushButton::clicked, this, [this]() { engineWebView->page()->save("save.html"); }); Then I tried a QWebEngineProfile::download() method: connect(saveButton, &QPushButton::clicked, this, [this]() { engineWebView->page

QTextDocument, QPdfWriter - how to scale output

☆樱花仙子☆ 提交于 2019-12-23 21:23:26
问题 I have createated a QTextDocument with a table in it. Now I'm trying to render it into PDF format using QPdfWriter (Qt 5.2.1). This is how I do it: QPdfWriter pdfWriter(output); QPainter painter(&pdfWriter); doc->drawContents(&painter); It works, but the problem is that the table in PDF is really, really tiny. What can I do to scale it up? I mean to scale up the whole document, not just this table, because I plan to add more contents to the document. 回答1: With current Qt (>= 5.3) you just

Taking Screenshot of Full Desktop with Qt5

走远了吗. 提交于 2019-12-23 21:06:30
问题 I figured out how to take a screenshot of the desktop today with Qt5 from an included example which gets the primary screen, grabs it, and then saves it. I'm translating the code from Python without testing so if there's a small syntax error, then yeah you know. So I can easily take a screenshot of the primary screen with: QApplication a(argv, argc); QScreen *screen = a.primaryScreen(); QPixmap screenshot = screen->grabWindow(0); screenshot.save('screenshot.png', 'png'); This will (obviously)