qt4

How to get Qt icon (QIcon) given a file extension

橙三吉。 提交于 2019-12-10 15:29:37
问题 I am developing an application that needs to display icons associated with different file types . Eg for .doc extensions, i need it to be able to display the Microsoft Word icon . QUESTION: How can I somehow get a QIcon from the system using QT sdk Thanks. 回答1: Use the QtGui.QFileIconProvider class. 回答2: Since Qt5, use QMimeDatabase for that: QMimeDatabase mime_database; QIcon icon_for_filename(const QString &filename) { QIcon icon; QList<QMimeType> mime_types = mime_database

Hiding bottom line in QTabBar

自作多情 提交于 2019-12-10 15:24:29
问题 There doesn't seem to be a way of setting a stylesheet for the bottom line (shown in the image below) of a QTabBar , which I want to be removed. How can I remove it? 回答1: Haven't used Qt in 6-7 months now so I'm not sure if this will work nor can I test it. Give QTabBar::drawBase a try. Plus the Qt library are very well documents so you should find a solution to your problems if you just carefully sift through it. Hope you are using the Qt SDK. 来源: https://stackoverflow.com/questions/11458431

QML How to put text cursor at the end of TextEdit element

梦想与她 提交于 2019-12-10 14:48:48
问题 I have a QML TextEdit element, I plan for append some text and put the cursor at the end. My method: import QtQuick 1.1 Rectangle { color: "black" anchors.fill: parent focus: false TextEdit { id: txtCommands color: "lightGreen" anchors.fill: parent textFormat: TextEdit.RichText wrapMode: TextEdit.WordWrap font.family: "Consolas" font.pixelSize: 15 focus: true MouseArea { anchors.fill: parent focus: false } Keys.onPressed: { console.log(event.text) switch (event.key) { case 16777234: // LEFT

LNK4099 linker warning with clean install of Qt SDK and Visual C++ 2008

只谈情不闲聊 提交于 2019-12-10 14:44:44
问题 Did a clean install on a new Windows 7 computer with: Visual Studio 2008 SP1 Qt SDK 1.1.4 Then I created a new project in Qt Creator. I picked "Qt Gui Application" under "Qt Widget Project" and had it target desktops with Visual C++ 2008, both debug & release (basically default settings). Then I pressed Build, and got.... qtmaind.lib(qtmain_win.obj):-1: warning: LNK4099: PDB 'vc90.pdb' was not found with 'c:\QtSDK\Desktop\Qt\4.7.4\msvc2008\lib\qtmaind.lib' or at 'C:\Users\JamesJ\Desktop

What is the use of “morph into” in qt?

匆匆过客 提交于 2019-12-10 14:43:41
问题 In qt gui editor, any gui component can be morphed into certain type of other gui components. But realistically speaking what is the practical use of this option? can it be done dynamically? if yes then what is the advantage of doing that? 回答1: The practical use is to quickly convert widgets into other, similar widgets. Let's say you have a group box filled with some widgets and you realize that you rather want a tab widget. Without morphing you would need to create a tab widget select all

How to completely disable or hide Back button in QWizard?

落花浮王杯 提交于 2019-12-10 14:34:40
问题 I want to disable or hide Back button in QWizard dialog. How can I do it? 回答1: I've looked at Qt's sources and found out that it's possible to hide Back button by creating custom button layout and ommiting Back button in the list: QList<QWizard::WizardButton> button_layout; button_layout << QWizard::HelpButton << QWizard::Stretch << QWizard::NextButton << QWizard::CustomButton1 << QWizard::CancelButton; this->setButtonLayout(button_layout); I hope this will save some time to somebody. P.S.

QFlags Enum Type Conversion fails all of a sudden

牧云@^-^@ 提交于 2019-12-10 14:16:36
问题 I've had this code running for quite a while in a library: MyClass::MyClass() : QDialog() { // (...) setWindowFlags( Qt::CustomizeWindowHint | Qt::WindowTitleHint ); // (...) } Then, after changing various parts of the library, I get this message all of a sudden: error C2664: 'QWidget::setWindowFlags': cannot convert parameter 1 from 'int' to 'Qt::WindowFlags' Apparently it doesn't find the | operator overload provided by the QFlags class so that the result of | returns an int rather than a

QT 4.5 - Changing the selection marquee for QGraphicsItem

亡梦爱人 提交于 2019-12-10 13:54:51
问题 Is it possible to define the style of the selection marquee when a QGraphicsItem is set selectd via setSelected(true)? 回答1: Technically no. After a quick look into Qt's source code, it seems that the standard item types QGraphics*Item have the dashed outline as a default behavior. You can work around this by subclassing your own QGraphicsItem. if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) qt_graphicsItem_highlightSelected(this, painter, option); I guess you can not

How to add check/Uncheck QAction in the context menu?

浪子不回头ぞ 提交于 2019-12-10 13:31:25
问题 I have created a context menu in Qt and I need the items in the menu works in a checked/Unchecked manner so that it toggles for every click on the respective item. How to add this feature to the QAction just like shown below? 回答1: Here is the relevant section from the manual. checkable : bool This property holds whether the action is a checkable action. A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An

Qt QGraphicsView unit testing - how to keep the mouse in a “pressed” state?

爱⌒轻易说出口 提交于 2019-12-10 13:25:32
问题 I have a fairly complex QGraphicsView/Scene setup where by I have items with complex interactions. As such I want to unit test this to avoid creating bugs in already existing functionality. For one test I wish to: Press the mouse down on an item in the scene Move the mouse to the right Release the mouse This will allow me to check that the item was selected, was moved by the correct amount, and was deselected. However I find that after sending mouseMove events the mouse state becomes