qt5

How to set background color of QComboBox button?

。_饼干妹妹 提交于 2020-07-09 10:45:53
问题 Version/Environment: Windows 10 64 bit Qt 5.11.0 MSVC2017 64 bit I have a simple QComboBox to enable/disable a feature: QComboBox *onOffComboBox = new QComboBox(); onOffComboBox->insertItem(0, "Off"); onOffComboBox->insertItem(1, "On"); The combo box is added as a cell widget to a table: this->ui->settingsTable->setCellWidget(rowNumber, 1, onOffComboBox); Now i want to change the background color of the button but not the select items. My first approach was simply to use QWidget 's

Can't call slot or Q_INVOKABLE from QML in subclass of QQmlPropertyMap

佐手、 提交于 2020-07-05 07:25:10
问题 I'm trying to test drive the QQmlPropertyMap class. It seems like it might work well for what I want, if I can subclass it. The documentation here even gives some rudimentary instructions on what to do for subclassing it. Said documentation also indicates that this class derives from QObject . For what it's worth, I'm using QtCreator 2.6.1 on Qt 5.0.0 with QtQuick 2.0. My main.qml: import QtQuick 2.0 Rectangle { width: 360 height: 360 Text { text: owner.field anchors.centerIn: parent }

Can't call slot or Q_INVOKABLE from QML in subclass of QQmlPropertyMap

ぃ、小莉子 提交于 2020-07-05 07:23:12
问题 I'm trying to test drive the QQmlPropertyMap class. It seems like it might work well for what I want, if I can subclass it. The documentation here even gives some rudimentary instructions on what to do for subclassing it. Said documentation also indicates that this class derives from QObject . For what it's worth, I'm using QtCreator 2.6.1 on Qt 5.0.0 with QtQuick 2.0. My main.qml: import QtQuick 2.0 Rectangle { width: 360 height: 360 Text { text: owner.field anchors.centerIn: parent }

CMAKE_PREFIX_PATH doesn't help CMake in finding Qt5

依然范特西╮ 提交于 2020-07-04 13:49:26
问题 From here: https://stackoverflow.com/a/28327499/462608 I tried this: cmake_minimum_required(VERSION 2.8.12) project(qtquick_hello_cmake) set(CMAKE_PREFIX_PATH "/opt/Qt5.9.1/5.9.1/") set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) find_package(Qt5 COMPONENTS Quick Core REQUIRED) qt5_add_resources(RESOURCES qml.qrc) add_executable(${PROJECT_NAME} "main.cpp" "qml.qrc") qt5_use_modules(${PROJECT_NAME} Quick Core) target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5:

QNetworkAccessManager without finished signal

有些话、适合烂在心里 提交于 2020-06-28 12:39:37
问题 I want to request and response directly instead of using connect(..,SLOT(finished()),..,SLOT()) 回答1: You can use a QEventLoop so that the application waits and can handle other events at the same time. #include <QCoreApplication> #include <QNetworkAccessManager> #include <QNetworkReply> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QNetworkAccessManager *manager = new QNetworkAccessManager; QEventLoop loop; QObject::connect(manager, &QNetworkAccessManager::finished, &loop

QNetworkAccessManager without finished signal

拟墨画扇 提交于 2020-06-28 12:38:04
问题 I want to request and response directly instead of using connect(..,SLOT(finished()),..,SLOT()) 回答1: You can use a QEventLoop so that the application waits and can handle other events at the same time. #include <QCoreApplication> #include <QNetworkAccessManager> #include <QNetworkReply> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QNetworkAccessManager *manager = new QNetworkAccessManager; QEventLoop loop; QObject::connect(manager, &QNetworkAccessManager::finished, &loop

Unknown type name QML_ELEMENT

别说谁变了你拦得住时间么 提交于 2020-06-28 07:59:22
问题 In the new Qt 5.15.0 there is a new declarative way to register C++ types for usage in QML. I followed the steps given in Qt Help (https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html#registering-an-instantiable-object-type) but it givens to me the following error: /.../randomnumbergenerator.h:10: error: ‘QML_ELEMENT’ does not name a type QML_ELEMENT ^~~~~~~~~~~ The class's definition is, for the moment: #ifndef RANDOMNUMBERGENERATOR_H #define RANDOMNUMBERGENERATOR_H #include <QObject

How to make a program with 2 windows that open simultaneously upon runtime in Qt?

情到浓时终转凉″ 提交于 2020-06-28 06:00:24
问题 Initially I made it in the main of the window I had made earlier 回答1: There is nothing complicated to open a 2 nd window (or dialog) with the main window. To demonstrate this, I made an MCVE. C++ source testQMainWindowWithQDialog.cc : // Qt header: #include <QtWidgets> class Dialog: public QDialog { private: QVBoxLayout _qVBox; QLabel _qLbl; public: Dialog(QWidget *pQParent = nullptr): QDialog(pQParent), _qLbl("the dialog") { setWindowTitle("the Dialog Window"); _qVBox.addWidget(&_qLbl, 1, Qt

QT - How to place widgets in mutually exclusive groups?

拈花ヽ惹草 提交于 2020-06-27 17:37:25
问题 I'm looking to do something like the following: example But with radio buttons instead of checkboxes. In the above picture widgets are placed into groups which can be enabled/disabled, but I want only 1 group to be enabled at a time (in the example both Group A and Group C are enabled). I did the above example using QGroupBox, but it only provides normal checkboxes, not radio buttons as far as I can tell. 回答1: The ckeckbox that appears in the QGroupBox is not a QCheckBox , it is just a

How do I draw a simple line in Qt3D?

亡梦爱人 提交于 2020-06-24 13:48:59
问题 I feel like this should be pretty straightforward, but for my life I can't figure out how to draw a basic line using Qt 3D. The only guidance I've been able to find on the subject is this obscure video, in which there's an off-putting amount of raw byte buffer and memory manipulation going on via scarcely documented classes. Is there a better way to do this using the shiny new API that I'm missing? 回答1: From the video you linked, I came up with the code below (also posted in Qt forums: https: