qt4

How to find global position of text cursor?

北慕城南 提交于 2019-12-08 19:12:05
问题 I would like to execute a QMenu object at the position of text cursor in a QPlainTextEdit. My problem is that QTextCursor is only define by its position in the Text (index of the character). How can I find global position of the QTextCursor ? Should I use an other object than QTextCursor in order to find the position of the text cursor where I want to open my QMenu ? Thank you by advance. 回答1: I've never tried myself, but doesn't QPlainTextEdit::cursorRect() work? It should give you position

Changing the cursor in a QGraphicsView

瘦欲@ 提交于 2019-12-08 16:41:28
问题 I'm trying to change the cursor of a QGraphicsView while the ScrollHandDrag is on, but it doesn't seem to work. I can change the cursor if I disable the ScrollHandDrag but not while it's active, I don't see what I could possibly be doing wrong... Bellow is a portion of code that reproduce the problem: QApplication app(argc, argv); QGraphicsScene scene; QRect rectangle(-8, -4, 100, 100); QPen pen(Qt::blue, 1, Qt::SolidLine); scene.addRect(rectangle, pen); scene.setBackgroundBrush(Qt::white);

Attach custom object to QStandardItem in Qt

空扰寡人 提交于 2019-12-08 16:34:52
问题 I'm using QTreeView to show some data to the user. What I want is to attach an actual object to each node represented using QStandardItem . To save the object reference into QStandardItem : QStandardItem *child = new QStandardItem(s); child->setFlags(child->flags() & ~Qt::ItemIsEditable); child->setData(QVariant(QVariant::UserType, i), Qt::UserRole + 10); To access the actual object when it is clicked in the UI: void MyOtherClass::handleTreeViewSelectionChanged(const QModelIndex &i) { MyClass

Qt string builder in for loop

匆匆过客 提交于 2019-12-08 16:23:32
问题 following this and this documentation I would use the QStringBuilder in a for loop. The code where I should apply it is QStringList words; QString testString; for (auto it = words.constBegin(); it != words.constEnd(); ++it) { testString += "[" + *it + "] "; } However I don't understand how I could write it to use the QStringBuilder as here I'm doing an assignment, instead the QStringBuilder requires me to use the % operator and do only one assignment following the docs. 回答1: AFAICS here,

Q_PROPERTY in Qt?

不羁的心 提交于 2019-12-08 16:22:37
问题 I cant really figure out why do I need it, Been reading: http://doc.qt.io/qt-4.8/properties.html#requirements-for-declaring-properties still cant really understand the use of it. any kind of help would be great! 回答1: Read about the Qt Property System , this is just like a usual class method but it can be used with Qt's meta-object system: QPushButton *button = new QPushButton; QObject *object = button; button->setDown(true); object->setProperty("down", true); Also these properties will be

Memory Management in Qt

岁酱吖の 提交于 2019-12-08 15:55:39
问题 HI all, I have small doubt about Qt memory management, Lets take an example of Listview, in listview we add each item by allocating memory dynamically. So in this case do we need to delete all the “new”ed items manually.. Eg: Qlistview *list = new Qlistview; QStandardItemModel *mModel = new QStandardItemModel(); list ->setModel(mModel); for(int I =0;i<10;i++) { QsandardItem *item = new QsandardItem(“Hi”); mModel->appendRow(item); } In this example, item should be deleted manually? 回答1:

How can we know the width and height of string?

醉酒当歌 提交于 2019-12-08 15:09:44
问题 I want to create a button exactly the same size as the string for this i want the width and height of the string. 回答1: To manually get the size of a string, you need to use the QFontMetrics class. This can be manually used like this: QFont font("times", 24); QFontMetrics fm(font); int pixelsWide = fm.width("What's the width of this text?"); int pixelsHigh = fm.height(); If you want to calculate it for the font used in a given widget (which you may not know), then instead of constructing the

mupdf and freetype: why are fonts blurred?

对着背影说爱祢 提交于 2019-12-08 14:46:14
问题 I would like to know if it is mupdf's or freetype2's fault if the font is blurred (even with antialiasing). This is using the pdfdraw utility on Windows. 回答1: As I mentioned in my other answer, the glyph description is composed of lines and curves. The problem is these lines and curves cannot ensure high fidelity glyph rendering at small sizes because there is not much space to represent the glyph. In this situation a technique called font hinting is used to render readable glyphs. TrueType

Qt::Tool window diasappears when application become inactive

你说的曾经没有我的故事 提交于 2019-12-08 14:10:32
问题 I have problem with keeping Qt::Tool window visible when the application becomes inactive. The application is running and there are 2 windows opened - main and additional with Qt::Tool flag set. When I open/switch to other app e.g Konosole the main window remains visible but second disappears - so if I want to e.g. rewrite some data from the tool window to a document I need to keep switching between them. There is no such problem with Qt::ToolTip but it looks different. I've also tried

How to build Qt5 app with their static libs?

穿精又带淫゛_ 提交于 2019-12-08 12:42:07
问题 I'm a Qt beginner and I want to know how to build Qt5 apps with their static libraries. Is that possible to build with static libs everything that can be build with dll's ?. I want to know because I don't want to install Qt libs everywhere where I want my apps to be running. For example I want to build with static libs app which code is in this post: Widgets must be created in the GUI thread Error !. How to correct the code? Is that possible ? How to do that ? 回答1: In order to use Qt as a