小编lci*_*kgl的帖子

如何在Qt StyleSheet中只覆盖一个属性:值对

我正在OSX Mavericks上编写新手Qt5代码,并且想要覆盖给定小部件的StyleSheet的一个属性:值对.

如果我运行以下自包含的演示代码:

#include <QApplication>
#include <QMainWindow>
#include <QtGui>
#include <QPushButton>

int
main( int argc, char *argv[] ) {
    QApplication app( argc, argv );

    QMainWindow* mw = new QMainWindow();

    QPushButton* AButton = new QPushButton( "A Button", mw );

    mw->show();

    return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

我得到了一个很好的按钮,默认为Macintosh风格 - 圆角,按下时标准OSX-蓝色等:

带有OSX默认值的QPushButton

但是,如果我设置样式表以使背景按钮颜色为红色,那么在此过程中我似乎失去了所有其他OSX样式默认值 - 没有更多的圆角,标准边距等:

#include <QApplication>
#include <QMainWindow>
#include <QtGui>
#include <QPushButton>

int
main( int argc, char *argv[] ) {
    QApplication app( argc, argv );

    QMainWindow* mw = new QMainWindow();

    QPushButton* AButton = new QPushButton( "A …
Run Code Online (Sandbox Code Playgroud)

qt qt5 qtstylesheets qpushbutton

15
推荐指数
2
解决办法
6178
查看次数

从C++ std :: vector中的线程中启动可运行对象

我有一个C++ 11程序,它配置了许多可运行的对象,将它们放在一个std::vector,然后在不同的线程中启动它们.不幸的是,当我迭代向量中的对象时,我只是为最后一个对象启动了线程.我已经在以下测试代码中将问题提炼到了核心(在OSX 10.9.5上clang++ -std=c++11 cpp_threadlaunch.cpp使用clang6.0 编译).

#include <iostream>
#include <thread>
#include <vector>
#include <unistd.h>

std::mutex  outputlock;

class agent {

public:
    agent(std::string name) : m_name(name) {};
    ~agent(void) {};

    void run(void) {
        while (1) {
            outputlock.lock();
            std::cout << "Agent: " << m_name << std::endl;
            outputlock.unlock();
            sleep(1);
        }
    }
    std::string     getName(void) { return m_name; }

private:

    std::string     m_name;
};

int main()
{
    std::vector<std::thread>        threads;
    std::vector<agent*>             agents;
    // std::string                  goal = "succeed";
    std::string                     goal = "fail";

    agents.push_back(new agent("A")); …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading vector c++11 stdthread

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

标签 统计

c++ ×1

c++11 ×1

multithreading ×1

qpushbutton ×1

qt ×1

qt5 ×1

qtstylesheets ×1

stdthread ×1

vector ×1