有一个应用程序可以通过QLabel和显示图片QPixmap。
有一个网站,您可以使用 上传照片Drag and Drop。
我怎样才能做到这一点,以便我可以将图像从我的应用程序拖放到站点?
也许图片需要以不同的方式显示?
有一个应用程序可以通过QLabel和显示图片QPixmap。
有一个网站,您可以使用 上传照片Drag and Drop。
我怎样才能做到这一点,以便我可以将图像从我的应用程序拖放到站点?
也许图片需要以不同的方式显示?
有两个块。一个块包含文本,另一个块只有一个稍微透明的背景。块可以相互重叠,并且由于一个块有背景,它与文本重叠,文本块不会滚动。我希望当块相交时,带有文本的块有一个滚动
.down-box {
position: fixed;
top: 0;
overflow: scroll;
}
.up-box {
position: fixed;
bottom: 0;
width: 100%;
background: green;
height: 50px;
opacity: 0.5;
}
<div class="wrapper">
<div class="down-box">
SCROLL<br>
SCROLL<br>
SCROLL<br>
SCROLL<br>
SCROLL<br>
SCROLL<br>
SCROLL<br>
SCROLL<br>
SCROLL<br>
</div>
<div class="up-box">
</div>
</div>
我想写一个脚本。用户点击站点窗口,我的脚本拦截了这个事件,处理它,但站点本身不再处理它。例如,用户点击了网站上的一个链接,我的脚本做出了反应,但是网站并没有以任何方式做出反应(也就是说,它没有重定向到任何地方)
我们以 Google Chrome 浏览器为例。当我们将光标移到选项卡上时,您可以(微弱地)看到它是如何逐渐变灰的,当然很快,但很顺利,当我们移开光标时,它又变白了。如何在中实现大致相同的QPushButton(即,将鼠标悬停在按钮上时平滑过渡到不同的颜色,当我移开光标时反之亦然)Qt?大概是通过了setStyleSheet,不过我的CSS和HTML不强,只是上网浏览器而已。
有以下代码:
dic = {'A':213, 'B':1424, 'F':412, 'Gs':asf}
for key in dic:
print(key)
你如何从第二个键开始迭代它?
或者,例如,使用 key F?
POST有这样的表格
type_list: Подавшие заявления
list_abitur: Бюджетная основа
faculty: Физический факультет
list_direction: 67
show_list: true
URL编码:
type_list: %D0%9F%D0%BE%D0%B4%D0%B0%D0%B2%D1%88%D0%B8%D0%B5+%D0%B7%D0%B0%D1%8F%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F
list_abitur: %D0%91%D1%8E%D0%B4%D0%B6%D0%B5%D1%82%D0%BD%D0%B0%D1%8F+%D0%BE%D1%81%D0%BD%D0%BE%D0%B2%D0%B0
faculty: %D0%A4%D0%B8%D0%B7%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B8%D0%B9+%D1%84%D0%B0%D0%BA%D1%83%D0%BB%D1%8C%D1%82%D0%B5%D1%82
list_direction: 67
show_list: true
import requests
import urllib
#Неработающие варианты
#Вариант 1
s = {"type_list":"Подавшие заявление","list_abitur":"Бюджетная основа", "faculty":"Физический факультет","list_direction":'67', "show_list":'true'}
req = requests.post('https://education.nsu.ru/abitura/',data=s)
print(req.text)
#Выводит null
#Вариант 2
req = requests.post('https://education.nsu.ru/abitura/',data={"type_list":urllib.parse.quote_plus("Подавшие заявление"),"list_abitur":urllib.parse.quote_plus("Бюджетная основа"), "faculty":urllib.parse.quote_plus("Физический факультет"),"list_direction":"67", "show_list":'true'})
print(req.text)
#Выводит null
什么算法将是最优化的?输入是一个 4 的数组,float输出是排序的。
添加:
有一个可以旋转的矩形和一条从其中心出来的直线。确定它穿过哪一侧。有4个临界角(由于周期是2π,而我用的是单位圆,直线到X轴的最大夹角可以是5.9999999 .. pi,但是其中一个临界角大于2π(例如,第三个角度,大约有 1.2 pi,我将矩形旋转 1.5 pi,然后我必须从临界角中减去 2 pi,以便将其与直线进行比较)我想做一个像这样检查
if (lineAngle > angles[3])
std::cout << "RIGHT";
else if (lineAngle > angles[2])
std::cout << "TOP";
else if (lineAngle > angles[1])
std::cout << "LEFT";
else if (lineAngle > angles[0])
std::cout << "DOWN";
例如,我有在不同头文件中声明的类。所有这些类都需要一个int变量。也就是说,这些类依赖于这个变量并且可以改变它。类将如何通过此变量相互影响。实现这一点的最佳方法是什么?
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QGraphicsView>
#include "graphicsscene.h"
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
private:
QGraphicsView *graph;
QWidget *buttonsWidget;
QWidget *statusWidget;
CustomScene *scene;
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
//mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
graph = ui->graphicsView; // Initialize pointer for graphics view
scene = new CustomScene(); // Тут ошибка
scene->setSceneRect(ui->graphicsView->rect()); // Set size and positon for scene
scene->addLine(0,0,200,200); // Test
graph->setScene(scene); // Set scene on graphics view
statusWidget = ui->StatusWidget; // Initialize pointer for own widget "Status Widget"
}
MainWindow::~MainWindow()
{
delete scene;
delete ui;
}
//graphicsscene.h
#ifndef GRAPHICSSCENE_H
#define GRAPHICSSCENE_H
#include <QObject>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
class CustomScene : public QGraphicsScene
{
Q_OBJECT
public:
explicit CustomScene(QObject *parent = 0);
~CustomScene();
signals:
// Сигнал для передачи координат положения курсора мыши
void signalTargetCoordinate(QPointF point);
public slots:
private:
// Функция, в которой производится отслеживание положения мыши
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
};
#endif // GRAPHICSSCENE_H
//graphicsscene.cpp
#include "graphicsscene.h"
CustomScene::CustomScene(QObject *parent) :
QGraphicsScene()
{
Q_UNUSED(parent);
}
CustomScene::~CustomScene()
{
}
void CustomScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
emit signalTargetCoordinate(event->scenePos());
}
给出错误消息:
mainwindow.obj:-1:错误:LNK2019:未解析的外部符号引用“public: __thiscall CustomScene::CustomScene(class QObject *)”(??0CustomScene@@QAE@PAVQObject@@@Z) 在函数“public: __thiscall MainWindow”中::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)`
如果你双击它,它会写Файл не найден в:mainwindow.obj.
如果我会在mainwindow.h我的声明CustomScene并在 中定义mainwindow.cpp,那么没有错误,但我如何确保其他文件中有 CustomScene?
#ifndef __GEOMETRY
#define __GEOMETRY
#include <iostream>
#include <cmath>
#define PI 3.14159265
template <typename T>
struct Vec2
{
union {
struct { T x, y; };
T raw[2];
};
Vec2() : x(0), y(0) {}
Vec2(T _x, T _y) : x(_x), y(_y) {}
Vec2(const Vec2<T> &vec): x(vec.x), y(vec.y){}
operator Vec2<int>() { return Vec2<int>(x + 0.5, y + 0.5); }
operator Vec2<float>() { return Vec2<float>(x, y); }
Vec2<T> operator + (const Vec2<T> &vec) { return Vec2<T>(x + vec.x, y + vec.y); }
Vec2<T> operator - (const Vec2<T> &vec) { return Vec2<T>(x - vec.x, y - vec.y); }
Vec2<T> operator * (const float value) { return Vec2<T>(x*value, y*value); }
Vec2<T> operator / (const T value) { return Vec2<T>(x / value, y / value); }
double operator * (const Vec2<T> &vec) { return x * vec.x + y * vec.y; }
T operator [] (int index) { if (index == 0) return x; else return y; }
friend std::ostream& operator << (std::ostream& ostr, const Vec2<T> &vec) {
ostr << "Vector: " << vec.x << " " << vec.y;
return ostr;
}
double length() { return sqrt(pow(x, 2) + pow(y, 2)); }
double angle() { return acos(x / length()) * 180 / PI; }
double angle_to(const Vec2<T> &vec) { return vec.length(); }
/* Выдает ошибку из-за того что я пишу "vec.length()"
Ошибка C2662 double Vec2<float>::length(void): невозможно преобразовать указатель "this" из "const Vec2<float>" в "Vec2<float> &" */
};
typedef Vec2<float> Vec2f
#endif
//main.cpp
#include <iostream>
#include "geo.h"
int main()
{
Vec2f test(2,4);
std::cout << test.angle_to(Vec2f(1,0));
return 0;
}
例如,我有Test.h一个类模板,其中定义了类模板,并且以隐式Test方式Test.cpp定义了类的方法和构造函数,但在main.cpp我初始化的某个地方Test<int> testValue。由于编译器不知道如何Type在Test.cpp. 一个人如何“作弊”(不使用额外的第三类文件.inl或其他任何东西)
测试.h
#ifndef Test
#define Test
template <class Type>
class Test
{
private:
Type value;
public:
Test(Type valueOfUser);
Type getValue();
};
#endif // Test
测试.cpp
#include "Test.h"
template <typename Type> Test<Type>::Test(Type valueOfUser): value(valueOfUser) {}
template <typename Type> Type Test<Type>::getValue () { return value; }
主文件
#include "Test.h"
intt main()
{
Test<int> test;
test.getValue();
return 0;
}
class Boo
{
public:
Boo()
{
Сделать X
}
Boo(int value)
{
Сделать Х
СделатЬ У
}
};
例如,我需要在构造函数中做一些事情。并且在这两个构造函数中有重复的代码。据我所知,有两种方法可以避免这种情况。
// 1 вариант
class Boo
{
public:
Boo()
{
Сделать X
}
Boo(int value):Boo()
{
СделатЬ У
}
};
// 2 Вариант
class Boo
{
public:
Boo()
{
doX();
}
Boo(int value)
{
doX();
Сделать У;
}
void doX()
{
Делает X;
}
};
哪一个更好?为什么 ?或者也许有更好的东西?
int main()
{
int *ptr = new int(5);
delete ptr;
// ptr становится висячим указателем.
std::cout << sizeof(ptr);
// у меня выводит 4 байта.
//
... какие-то действия в коде
//
}
我声明了一个指针,它在我的内存中占用 4 个字节,在正文开头的某个地方删除它(据我所知,删除只是释放指针所在的内存),指针本身会发生什么?为什么它仍然占用一些内存?毕竟,如果我创建一百个指针,删除它们,它们仍然会占用一些空间,这会影响我的程序的速度。
在这里,其实算法是一样的。连接了一个处理图像的库。
for (int i=0; i<total_height; i++) {
bool second_half = i>t1.y-t0.y || t1.y==t0.y;
int segment_height = second_half ? t2.y-t1.y : t1.y-t0.y;
float alpha = (float)i/total_height;
float beta = (float)(i-(second_half ? t1.y-t0.y : 0))/segment_height; // be careful: with above conditions no division by zero here
Vec2i A = t0 + (t2-t0)*alpha;
Vec2i B = second_half ? t1 + (t2-t1)*beta : t0 + (t1-t0)*beta;
if (A.x>B.x) std::swap(A, B);
for (int j=A.x; j<=B.x; j++) {
image.set(j, t0.y+i, color); // attention, due to int casts t0.y+i != A.y
}
}
我想画一个三角形并填充它。这里的坐标系是三维的,起点在左下角(和学校一样,Y轴在上,X轴在右,Z轴不知道,从我们还是in我们)。我从顶部开始,这是最低的。我把三角形分成两半。在 Y 中上升一个像素并将其从特定的 Ax 填充到另一个特定的 Bx 。这来自文章https://habr.com/post/248159/。
重写使得迭代器最初不等于0,而是顶点的Y坐标,它的Y坐标较小
for(int y = t0.y; y <= t2.y; y++)
{
bool first_half = y <= t1.y;
int segment_height = first_half ? (t1.y - t0.y):(t2.y - t1.y);
float beta = (y - (first_half ? t0.y:t1.y))/static_cast<float>(segment_height);
float alpha = (y - t0.y)/static_cast<float>(total_height);
Vec2i A = t0 + (t2 - t1)*alpha;
Vec2i B = first_half ? (t0 + (t1 - t0)*beta) : (t1 + (t2 - t1)*beta);
if (A.x > B.x) std::swap(A,B);
for (int j = A.x; j < B.x; j++)
image.set(j, y, color);
}
如果三角形的数量很少。该差异约为 0.05 秒。如果有超过一万个三角形,我从不等程序完成。但是使用文章中的算法,程序执行时间就像我画几个三角形一样。这是功能
void triangle(Vec2i t0, Vec2i t1, Vec2i t2, TGAImage &image, TGAColor color) {
if (t0.y==t1.y && t0.y==t2.y) return; // i dont care about degenerate triangles
if (t0.y>t1.y) std::swap(t0, t1);
if (t0.y>t2.y) std::swap(t0, t2);
if (t1.y>t2.y) std::swap(t1, t2);
int total_height = t2.y-t0.y;
for (int i=0; i<total_height; i++) {
bool second_half = i>t1.y-t0.y || t1.y==t0.y;
int segment_height = second_half ? t2.y-t1.y : t1.y-t0.y;
float alpha = (float)i/total_height;
float beta = (float)(i-(second_half ? t1.y-t0.y : 0))/segment_height; // be careful: with above conditions no division by zero here
Vec2i A = t0 + (t2-t0)*alpha;
Vec2i B = second_half ? t1 + (t2-t1)*beta : t0 + (t1-t0)*beta;
if (A.x>B.x) std::swap(A, B);
for (int j=A.x; j<=B.x; j++) {
image.set(j, t0.y+i, color); // attention, due to int casts t0.y+i != A.y
}
}
}
从文章。
我不明白为什么程序执行时间会有这样的差异。你能解释一下吗
for(int j = 0; j < 100;)
{
for (int i = 0; i < 500; j++)
{
//Что-то происходит
}
}
// 相同的循环,只有 i 被声明为 500。
for (int j = 0; j < 100; j++)
{
for (int i = 500; i < 1000; i++)
{
//Происходит тоже самое, что и в цикле выше
}
}
我不是从 0 而是从 500 声明“i”这一事实会影响编译速度吗?在这种情况下,“i”本身不参与循环。我不在循环体中使用变量。