Код: Выделить всё
W libQtAndroid01_x86_64.so: QWidget::paintEngine: Should no longer be called
W libQtAndroid01_x86_64.so: QPainter::begin: Paint device returned engine == 0, type: 1
W libQtAndroid01_x86_64.so: QPainter::setBrush: Painter not active
W libQtAndroid01_x86_64.so: QPainter::resetMatrix: Painter not active
W libQtAndroid01_x86_64.so: QPainter::translate: Painter not active
W libQtAndroid01_x86_64.so: QPainter::rotate: Painter not active
W libQtAndroid01_x86_64.so: QPainter::drawRects: Painter not active
W libQtAndroid01_x86_64.so: QPainter::end: Painter not active, aborted
Вот мой собственный заголовок виджета:
Код: Выделить всё
#ifndef ROTATABLESQUARE_H
#define ROTATABLESQUARE_H
#include
#include
class RotatableSquare : public QPlainTextEdit
{
Q_OBJECT;
private:
int rotate_degree = 0;
public:
RotatableSquare(QWidget *parent = nullptr);
public:
int GetRotateDegree() const;
void SetRotateDegree(int deg);
protected:
virtual void paintEvent(QPaintEvent* event) override;
};
#endif // ROTATABLESQUARE_H
Код: Выделить всё
#include "rotatablesquare.h"
#include
#include
RotatableSquare::RotatableSquare(QWidget* parent) : QPlainTextEdit(parent)
{
}
int RotatableSquare::GetRotateDegree() const
{
return rotate_degree;
}
void RotatableSquare::SetRotateDegree(int deg)
{
rotate_degree = deg;
}
void RotatableSquare::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setBrush(QColor(249,249,249));
painter.resetTransform();
painter.translate((this->width() / 2), (this->height() / 2));
painter.rotate(rotate_degree);
painter.drawRect(this->geometry());
painter.end();
}
Код: Выделить всё
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created by: Qt User Interface Compiler version 6.8.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include
#include
#include
#include
#include
#include
#include
#include
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralwidget;
QCommandLinkButton *btn_get_res;
QLabel *label;
QLabel *text_res;
QPushButton *btn_do_rotate;
RotatableSquare *pte_rotate;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName("MainWindow");
MainWindow->resize(800, 600);
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName("centralwidget");
btn_get_res = new QCommandLinkButton(centralwidget);
btn_get_res->setObjectName("btn_get_res");
btn_get_res->setGeometry(QRect(110, 250, 172, 41));
label = new QLabel(centralwidget);
label->setObjectName("label");
label->setGeometry(QRect(130, 190, 40, 31));
text_res = new QLabel(centralwidget);
text_res->setObjectName("text_res");
text_res->setGeometry(QRect(180, 190, 241, 31));
btn_do_rotate = new QPushButton(centralwidget);
btn_do_rotate->setObjectName("btn_do_rotate");
btn_do_rotate->setGeometry(QRect(490, 270, 80, 18));
pte_rotate = new RotatableSquare(centralwidget);
pte_rotate->setObjectName("pte_rotate");
pte_rotate->setGeometry(QRect(480, 120, 104, 104));
MainWindow->setCentralWidget(centralwidget);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
btn_get_res->setText(QCoreApplication::translate("MainWindow", "\350\216\267\345\217\226\345\261\217\345\271\225\345\210\206\350\276\250\347\216\207", nullptr));
label->setText(QCoreApplication::translate("MainWindow", "\345\210\206\350\276\250\347\216\207\357\274\232", nullptr));
text_res->setText(QCoreApplication::translate("MainWindow", "TextLabel", nullptr));
btn_do_rotate->setText(QCoreApplication::translate("MainWindow", "\350\275\254\345\234\210\345\234\210~", nullptr));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
Код: Выделить всё
cmake_minimum_required(VERSION 3.16)
project(QtAndroid01 VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Gui)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Gui)
INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}
)
set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
rotatablesquare.h
rotatablesquare.cpp
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(QtAndroid01
MANUAL_FINALIZATION
${PROJECT_SOURCES}
rotatablesquare.h rotatablesquare.cpp
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET QtAndroid01 APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(QtAndroid01 SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(QtAndroid01
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(QtAndroid01 PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Gui)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.QtAndroid01)
endif()
set_target_properties(QtAndroid01 PROPERTIES
${BUNDLE_ID_OPTION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
include(GNUInstallDirs)
install(TARGETS QtAndroid01
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(QtAndroid01)
endif()
Моя версия Qt — 6.8.0
Подробнее здесь: https://stackoverflow.com/questions/793 ... in-android