我是 React 的新手,正在尝试构建一个应用程序,我想在其中按下一个自定义按钮,该按钮将打开一个文件对话框并在选择它时上传文件。这是我的代码:
class ComposeButtons extends Component{
constructor(props) {
super(props);
this.state={
selectedFile: null
};
this.myInput = React.createRef();
}
fileSelectedHandler = (event) => {
console.log(event.target.files[0]);
this.setState({
selectedFile: event.target.files[0]
})
};
triggerClick = () => {
this.myInput.current.click()
};
fileUploadHandler = () => {
/* file upload triggered */
console.log('file upload triggered');
};
render() {
return(
<div className={"composeForm-area"}>
<div>
<Input
style={{display:'none'}}
type={"file"}
onChange={this.fileSelectedHandler}
ref={this.myInput}
/>
<Button onClick={this.triggerClick}
onChange={this.fileUploadHandler}
style={{ backgroundColor: '#DDDCDC'}}>
<Icon style={{ fontSize: '20px'}} type="camera" />
</Button>
</div>
</div>
)
}
} …Run Code Online (Sandbox Code Playgroud) 我按照 Bryan Oakley 的代码在此处向文本小部件添加行号功能。我正在该文本框中插入我自己的 XML 文件。该文件列出如下:
myFile.xml
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<p1:sample1 xmlns:p1="http://www.example.org/eHorizon">
<p1:time nTimestamp="5">
<p1:location hours = "1" path = '1'>
<p1:feature color="6" type="a">560</p1:feature>
<p1:feature color="2" type="a">564</p1:feature>
<p1:feature color="3" type="b">570</p1:feature>
<p1:feature color="4" type="c">570</p1:feature>
</p1:location>
</p1:time>
<p1:time nTimestamp="6">
<p1:location hours = "1" path = '1'>
<p1:feature color="2" type="a">564</p1:feature>
<p1:feature color="3" type="b">570</p1:feature>
<p1:feature color="4" type="c">570</p1:feature>
</p1:location>
</p1:time>
</p1:sample1>
Run Code Online (Sandbox Code Playgroud)
myCode.py
import Tkinter as tk
class TextLineNumbers(tk.Canvas):
def __init__(self, *args, **kwargs):
tk.Canvas.__init__(self, *args, **kwargs)
self.textwidget = None
def attach(self, text_widget): …Run Code Online (Sandbox Code Playgroud) 这可能听起来没有问题,但我是Qt的新手,并且在使用C++进行编程方面有一些经验.我在最近两天努力奋斗只是为了在QT中制作简单的gui来从现有的C++程序中获取值.
我在下面给出了示例ui,并且当用户按下按钮时我想在文本字段中存储来自c ++文件的字符串值.
mainwindow.ui
应该从存储在StoreValue字符串变量中的c ++程序下面获取应存储在空文本框中的值:
HELLO.CPP:
#include <string>
#include <iostream>
class helloWorld
{
public:
std::string hello(){
std::string StoreValue = "Hello World!"; // print this value in text box
return StoreValue;
}
};
Run Code Online (Sandbox Code Playgroud)
目前在Qt我的项目的源文件夹中我添加了这个额外的hello.cpp文件以及默认的mainwindow.cpp.还存在mainwindow.ui文件,它只是上面提到的GUI中组成的组件的xml结构.
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
Run Code Online (Sandbox Code Playgroud)
最后我的
mainwindow.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>321</width>
<height>117</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget …Run Code Online (Sandbox Code Playgroud)