小编Bow*_*one的帖子

QFontMetrics返回的结果不准确

QTableWidget如果用户搜索了某些内容,我将有一个自定义委托来突出显示匹配项。不幸的是,矩形位置通常并不真正适合。这发生在某些字符或短语上,或者取决于匹配项的数量或前导字符串的大小。我找不到造成此问题的特定原因。这是一个例子:例。

这是我的绘画例程(尝试修复该问题的所有反复试验都有些混乱):

void custom_delegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const{

    const QTableWidget* table_widget = qobject_cast<const QTableWidget*>(qstyleoption_cast<const QStyleOptionViewItemV3*>(&option)->widget);
    const int cell_width = table_widget->columnWidth(index.column());

    // basic table cell rectangle
    QRect rect_a = option.rect;

    // adjust rectangle to match text begin
    QStyle* style;
    if(table_widget != 0){
        style = table_widget->style();
    }else{
        style = QApplication::style();
    }
    const int text_horizontal_margin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, table_widget) + 1;
    QRect rect_b = rect_a.adjusted(text_horizontal_margin, 0, -text_horizontal_margin, 0);

    // adjust rectangle to match text height
    QFont cell_font …
Run Code Online (Sandbox Code Playgroud)

c++ qt fontmetrics

5
推荐指数
1
解决办法
1979
查看次数

如何在laravel 5.1刀片中回显字符串和变量

我在我的PHP文件中使用此代码:

university.blade.php

{{ url( $universities->universityName.'/students') }}" >
Run Code Online (Sandbox Code Playgroud)

问题是只显示http://localhost:8000/students,而不是变量的值。那么解决方法是什么呢?

php laravel

5
推荐指数
1
解决办法
2万
查看次数

qt creator opencv windows cmake错误

我想为qt creator配置然后生成opencv库以链接它们.我打开了cmake 3.1.0并输入了源代码和构建路径.

资源:

C:/Users/Philipp_Laptop/Downloads/opencv/sources
build: C:/opencv-mingw
Run Code Online (Sandbox Code Playgroud)

然后我用路径配置了mingw-compiler:

C:/Qt/Tools/mingw482_32/bin/gcc.exe
C:/Qt/Tools/mingw482_32/bin/g++.exe
Run Code Online (Sandbox Code Playgroud)

配置成功后,我设置了with_Qt选项.我配置了两次,它显示以下错误:


Detected version of GNU GCC: 48 (408)
CMake Warning (dev) at cmake/OpenCVUtils.cmake:261 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "WIN32" will no longer be dereferenced when the
  policy is set to NEW.  Since the policy is not set …
Run Code Online (Sandbox Code Playgroud)

c++ qt opencv cmake qt-creator

4
推荐指数
1
解决办法
6132
查看次数

requests.exceptions.SSLError: [Errno 2] 没有这样的文件或目录

我正在使用一个名为“Tweetpony”的 Python 库;一切正常,除了当我使用 Pyinstaller 打包我的脚本时,我在执行时收到以下错误:

Traceback (most recent call last):
  File "<string>", line 13, in <module>
  File "C:\Users\Demitri\Desktop\TWE\build\fetch\out00-PYZ.pyz\tweetpony.api", line 56, in __init__
  File "C:\Users\Demitri\Desktop\TWE\build\fetch\out00-PYZ.pyz\tweetpony.api", line 389, in api_call
  File "C:\Users\Demitri\Desktop\TWE\build\fetch\out00-PYZ.pyz\tweetpony.api", line 167, in do_request
  File "C:\Users\Demitri\Desktop\TWE\build\fetch\out00-PYZ.pyz\requests.api", line 65, in get
  File "C:\Users\Demitri\Desktop\TWE\build\fetch\out00-PYZ.pyz\requests.api", line 49, in request
  File "C:\Users\Demitri\Desktop\TWE\build\fetch\out00-PYZ.pyz\requests.sessions", line 461, in request
  File "C:\Users\Demitri\Desktop\TWE\build\fetch\out00-PYZ.pyz\requests.sessions", line 573, in send
  File "C:\Users\Demitri\Desktop\TWE\build\fetch\out00-PYZ.pyz\requests.adapters", line 431, in send
requests.exceptions.SSLError: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)

我已经尝试按照这些人的建议在 .spec 文件中分配 'caceret.pem' https://github.com/kennethreitz/requests/issues/557 但它没有帮助。

import tweetpony, …
Run Code Online (Sandbox Code Playgroud)

python pyinstaller

4
推荐指数
1
解决办法
1万
查看次数

在python中从json获取密钥

我有一个 API,它的响应是这样的 json:

{
"a":1,
"b":2,
"c":[
     {
     "d":4,
     "e":5,
     "f":{
         "g":6
         }
     }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能编写一个 python 程序,它会给我钥匙['d','e','g']。我试过的是:

jsonData = request.json() #request is having all the response which i got from api
c = jsonData['c']
for i in c.keys():
    key = key + str(i)
print(key)
Run Code Online (Sandbox Code Playgroud)

json python-2.7

4
推荐指数
1
解决办法
1万
查看次数

android TrafficStats getUidRxBytes不正确

我写了一个小小的android应用程序,发送Http请求,从服务器接收响应,并计算了发送和接收的字节数。代码简单如下

long receivedBytes = TrafficStats.getUidRxBytes(uid)-lastNumer
Run Code Online (Sandbox Code Playgroud)

我发现ReceivedBytes总是大于http Header + http Body,例如我在服务器中捕获(使用wireshark)的实际http帧大小为1645 bytes(header + body),但是android API返回的receiveBytes为1912,因此作为传输。

TrafficStats getUidRxBytes本身不准确(可能是此问题特定于我的带有cynogenmod 10.3的平台i9300)

最后,我找到了计算数据使用量的正确方法,我发现了其他方法来计算数据使用量,这似乎比TrafficStats API更准确。(非常感谢here)

private long[] getStat() {
    String line, line2;
    long[] stats = new long[2];
    try {
        File fileSnd = new File("/proc/uid_stat/"+uid+"/tcp_snd");
        File fileRcv = new File ("/proc/uid_stat/"+uid+"/tcp_rcv");
        BufferedReader br1 = new BufferedReader(new FileReader(fileSnd));
        BufferedReader br2 = new BufferedReader(new FileReader(fileRcv));
        while ((line = br1.readLine()) != null&& (line2 = br2.readLine()) != null) {
            stats[0] = Long.parseLong(line);
            stats[1] = Long.parseLong(line2);
        }
        br1.close();
        br2.close();
    } …
Run Code Online (Sandbox Code Playgroud)

android http frame

3
推荐指数
1
解决办法
1692
查看次数

PHP缓存包含文件

我在test.php中有以下测试代码:

<?php
$step = $_GET['step'];
switch($step) {
  case 1:
    include 'foo.php';   # line 5
    file_put_contents('foo.php', '<?php print "bar\\n"; ?>');
    header('Location: test.php?step=2');
  break;
  case 2:
    print "step 2:\n";
    include 'foo.php';
  break;
}
?>
Run Code Online (Sandbox Code Playgroud)

foo.php最初有以下内容:

<?php print "foo\n"; ?>
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中调用test.php?step = 1时,我希望得到以下输出:

step 2:
bar
Run Code Online (Sandbox Code Playgroud)

但我得到这个输出:

step 2:
foo
Run Code Online (Sandbox Code Playgroud)

当我在第5行注释掉include时,我得到了理想的结果.结论是,PHP缓存了foo.php的内容.当我用step = 2重新加载页面时,我也得到了所需的结果.

现在......为什么这样以及如何避免这种情况?

php caching

3
推荐指数
2
解决办法
3474
查看次数

当用户尝试激活 MainWindow 时引发模态 QDialog

我们有一个QMainWindow,其中包含几个QDialog,这些 QDialog 使用exec()打开,因此是模态的(这是所需的行为)。

现在,当用户打开这些对话框之一,选择与某些与对话框重叠但不与主窗口重叠的外部程序(例如网络浏览器)进行交互,然后尝试返回到我们的程序时,他无法通过单击由于模式对话框而导致的主窗口的可见区域。为了返回,他需要移动/最小化阻碍 QDialog 视图的其他窗口或使用任务栏激活它。这可能会给人留下程序被冻结的印象(特别是如果已经过去了一段时间并且用户不知道打开的对话框)。

在这种情况下,我在主窗口/对话框中重载了各种焦点/鼠标事件以 raise() QDialog,但在显示对话框时单击主窗口时我找不到激活的事件。有人知道这个问题的解决方案吗?我认为到目前为止我一定忽略了一些简单的事情。

c++ qt modal-dialog qt4.6

2
推荐指数
1
解决办法
599
查看次数

只重写URL的中间部分 - mod重写.htaccess

我想cadeaushop将网址中的部分更改为hobby-cadeau-shop.我在htaccess文件中进行了以下mod重写:

RewriteRule ^cadeaushop/(.*) http://www.zovyo.nl/hobby-cadeau-shop/$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)

它工作得很好,但在一个地方我想要别的东西.购物车使用https,一个安全的网址.现在这个url也设置为http.

如何更改mod重写,以便url的第一部分不会更改?我试过一些改变,比如

RewriteRule ^cadeaushop/(.*) /hobby-cadeau-shop/$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)

但这不起作用.

提前致谢.

此致,马丁

apache .htaccess mod-rewrite

2
推荐指数
1
解决办法
7059
查看次数

pandas MonthOffset 不起作用

不确定这是否是一个错误,但pd.tseries.offsets.MonthOffset()似乎提供了错误的结果。它增加日而不是月。

import pandas as pd

ts = pd.Timestamp('2015-07-15')
print(ts)

2015-07-15 00:00:00


ts1 = ts + pd.tseries.offsets.MonthOffset(1)
print(ts1)

2015-07-16 00:00:00
Run Code Online (Sandbox Code Playgroud)

python pandas

2
推荐指数
1
解决办法
2521
查看次数