qt4

How to load a web page from resources in Qt?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 11:53:20
问题 If we put a webpage in resources, how can we load it in webkit? 回答1: I don't know if I understood correctly, but I suppose you have a web page like a test.html file, and you want it to be loaded in a QWebView. This is quite simple: #include <QtGui/QApplication> #include <QWebView> int main(int argc, char* argv[]) { QApplication a(argc, argv); QWebView view; view.setUrl(QUrl("qrc:/test.html")); view.show(); return a.exec(); } The file has to be placed in a Qt resource file. Remember to add: QT

QGraphicsView scroll problem

守給你的承諾、 提交于 2019-12-10 11:26:46
问题 I have the following situation here: I do some drawing on a graphics scene, in one type of central widget, and some times this also involves scrolling the scene. Then the user clicks somewhere else in the application, the central widget is changed to something else (and the graphic views' scroll bar positions are saved somewhere). Now, the user wants to click back to the graphics scene, I redraw the scene (by recreating the entire graphics view window, because when the user was outside of the

“cannot find -ljscore” while I am trying to build Qt 4.7.1 static library

不打扰是莪最后的温柔 提交于 2019-12-10 11:05:28
问题 I tried to build static Qt library from the latest source, but got the following error: /usr/bin/ld: cannot find -ljscore collect2: ld returned 1 exit status How to solve this problem? 回答1: That's a bug in Qt's build system existing since 4.7.0 and not fixed in 4.7.1. After the failing make call, you have to copy libjscore.a and libjscore.prl (don't know their exact locations, search the Qt build tree to find them, somewhere in webkit) to the lib/ folder and rerun make. 回答2: I had the exact

Can't pass QMap through to SLOT

心不动则不痛 提交于 2019-12-10 10:42:47
问题 So, this works: .h public slots: void addMenu(QString passedName); signals: void clicked(const QString &text); .cpp signalMapper = new QSignalMapper(this); signalMapper->setMapping(button, QString("passed_value")); connect(button, SIGNAL(clicked()), signalMapper, SLOT(map())); connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(addMenu(QString))); Now, I am trying to pass a QMap < QString, QString > through to addMenu instead of just a QString, but I get the error: no matching function

Get time of execution piece of code

感情迁移 提交于 2019-12-10 10:42:47
问题 How do I get milliseconds time of execution of a piece of code in Qt/C++? 回答1: Use the QTime class. Start it with .start() (or .restart() ) and then check the amount of milliseconds passed with .elapsed() . Naturally, the precision ultimately depends on the underlying OS, although with the major platforms you should have no trouble getting a real millisecond resolution. 回答2: If you are running on a Windows system, then you can use timer based on the Windows Performace Timers and get

How to change text alignment in QTabWidget in C++?

半世苍凉 提交于 2019-12-10 10:26:37
问题 This is the same question as in: How to change text alignment in QTabWidget? I tried to port that python code into C++ but it doesn't seem to work. Here is header file: #include <QTabBar> class HorizontalTabWidget : public QTabBar { Q_OBJECT public: explicit HorizontalTabWidget(QWidget *parent = 0); protected: void paintEvent(QPaintEvent *); QSize sizeHint() const; }; Here is source file: void HorizontalTabWidget::paintEvent(QPaintEvent *) { for(int index = 0; index < count(); index++) {

Embed xterm into QWidget and communicate with it

a 夏天 提交于 2019-12-10 09:59:14
问题 I want to embed an xterm into a pyqt4 widget and communicate with it. Especially I want to be able to print to it and execute commands on it (such that it returns to normal user prompt after executing the command just like a normal shell would do). Consider the following minimal example. How can I make it work? #!/usr/bin/env python #-*- coding:utf-8 -*- import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class embedxterm(QWidget): def __init__(self): QWidget.__init__(self) self

Adding custom widgets to QMenuBar

﹥>﹥吖頭↗ 提交于 2019-12-10 09:24:49
问题 Qt3 used to provide QMenuBar::insertItem with QWidget* parameter. This way any custom widget could be added to menu bar - for example a clock-widget. In Qt4 there is no such overloaded method. What would be the best way to reach the same goal - adding custom widgets to a menu bar? The custom widgets should be integrated in the layout of menu bar. Does anyoune knows the background, why this overload of insertItem was removed in Qt4 API? Best regards. 回答1: there's a QMenuBar::addAction (

Can't compile Qt with Microsoft compiler

ぃ、小莉子 提交于 2019-12-10 09:23:34
问题 I want to build Qt (4.7.3) with the VS2010 compiler but ran into a problem while configuring. I’m using the VS-command-shell. My configure-command looks like this: configure.exe -platform win32-msvc2010 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support This happens like a second after starting configure. What is going wrong? C:\qt-everywhere-opensource-src-4.7.3\qmake\qbitarray.obj couldn't be found werden del project.obj main.obj makefile.obj

How to make a QImage or QPixmap semi-transparent - or why is setAlphaChannel obsolete?

微笑、不失礼 提交于 2019-12-10 04:19:17
问题 4.7 and like to overlay two images on a qgraphicsview. The image on top shall be semi-transparent to allow to see through it. Initially both images are fully opaque. I expected some function for setting a global alpha-value for each pixel to exist, but it seems like there is no such function. The closest thing to it is QPixmap::setAlphaChannel(const QPixmap & alphaChannel), which, however, is marked as obsolete since Qt-4.6. Instead the manual refers to the CompositionModes of QPainter, but I