qwidget

Using an alpha transparent mask on a QWidget?

别来无恙 提交于 2019-12-02 01:14:07
Is it possible to assign an alpha-transparent mask to a QWidget? I know how to set a mask using setMask but it seems it only supports black&white masks. Is it possible to make it support a true alpha channel? i.e. currently I have a PNG like this: and a widget like this: If I load my PNG in a QPixmap and set it as a mask, I get this (notice the edges): However I would like to get this (smooth edges): Any idea how to do that? Note: I'm doing some more complex drawing on the widget, which must be restricted to the mask area, so I cannot simply set my PNG as the widget's background image. sam-w I

Qt 4.4: disabled widgets receiving mouse events

喜你入骨 提交于 2019-12-02 01:02:11
问题 As the title suggests, is there a way for a disabled widget to receive mouse events? I'm using QWidget::setEnabled() for changing the appearance of widgets but I still want to receive their mouse events. Thanks in advance :) 回答1: You can do this with an event filter on the widget in question. See QObject::eventFilter(). Your implementation might look something like this: bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (ui->pushButton) { if (event->type() == QEvent:

Qt 4.4: disabled widgets receiving mouse events

时间秒杀一切 提交于 2019-12-01 23:47:13
As the title suggests, is there a way for a disabled widget to receive mouse events? I'm using QWidget::setEnabled() for changing the appearance of widgets but I still want to receive their mouse events. Thanks in advance :) You can do this with an event filter on the widget in question. See QObject::eventFilter() . Your implementation might look something like this: bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (ui->pushButton) { if (event->type() == QEvent::MouseButtonRelease) { qDebug() << "mouse button"; return true; } else { return false; } } else { // pass the event on

Qt - How to convert from QObject to UI elements?

时光怂恿深爱的人放手 提交于 2019-12-01 22:09:59
I am working in Qt 4.7, and I have a QWidget object in my dialog. I need to go through each of the children and extract the current text into a QStringList. Every other object is a QCheckBox, and the rest are QComboBoxes (I would just need the text portion of both). So far the only way I could think of to do this would be to use the children() function to get them as QObject*'s and cast them, like this: QStringList textlist; for(int i = 0; i < ui->myWidget->children().size(); i++) { if(i % 2 == 0) { QCheckBox *q = (QCheckBox *)ui->myWidget->children().at(i); textlist.append(q->text()); } else

Can QWidget::find find widgets from a different process?

最后都变了- 提交于 2019-12-01 19:39:33
The documentation for QWidget::winId states (among other things) "If a widget is non-native (alien) and winId is invoked on it, that widget will be provided a native handle." I'm not sure what 'alien' means in that context, but I'm choosing to ignore it for now. :) So assuming that my widget now has a valid native handle associated with it, can I then pass that native handle to another process and into QWidget::find and get a valid QWidget object back within that second process? I probably don't need to do too much else to the widget in the second process other than show/hide it and attach it

Using any c++ function as a Qt slot

风流意气都作罢 提交于 2019-12-01 15:17:06
Is there a way to use any C++ function as a Qt slot, without having its class inheriting from QWidget? pnezis You cannot in Qt versions < Qt 5. In order to use signals/slots the meta object compiler has to be invoked. To make this happen your class should meet the following requirements: Inherit from QObject or any other subclass (eg QWidget , QPushButton etc) The Q_OBJECT macro should be defined in the private section of the class in order to enable meta-object features such as slots Use the Qt keywords slots and signals in order to declare which functions should be handles by the meta

Using any c++ function as a Qt slot

泄露秘密 提交于 2019-12-01 15:03:47
问题 Is there a way to use any C++ function as a Qt slot, without having its class inheriting from QWidget? 回答1: You cannot in Qt versions < Qt 5. In order to use signals/slots the meta object compiler has to be invoked. To make this happen your class should meet the following requirements: Inherit from QObject or any other subclass (eg QWidget , QPushButton etc) The Q_OBJECT macro should be defined in the private section of the class in order to enable meta-object features such as slots Use the

How can I add resizable widgets in Qt Creator?

让人想犯罪 __ 提交于 2019-12-01 13:35:49
How can I add resizable widgets in Qt Creator? Specially widgets in QVBoxLayout or QHBoxLayout Example: int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget* w = new QWidget; QVBoxLayout* l = new QVBoxLayout; w->setLayout(l); QPushButton* b = new QPushButton("hello"); b->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); l->addWidget(b); w->show(); return app.exec(); } André Puel You must use layouts if you want that your widgets are resizable: http://doc.qt.io/qt-5/layout.html 来源: https://stackoverflow.com/questions/7195781/how-can-i-add-resizable-widgets-in-qt

How can I add resizable widgets in Qt Creator?

时间秒杀一切 提交于 2019-12-01 11:58:57
问题 How can I add resizable widgets in Qt Creator? Specially widgets in QVBoxLayout or QHBoxLayout 回答1: Example: int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget* w = new QWidget; QVBoxLayout* l = new QVBoxLayout; w->setLayout(l); QPushButton* b = new QPushButton("hello"); b->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); l->addWidget(b); w->show(); return app.exec(); } 回答2: You must use layouts if you want that your widgets are resizable: http://doc.qt.io

Show Qt3D stuff inside QWidget in Qt5

橙三吉。 提交于 2019-12-01 11:47:39
So I felt all warm and fuzzy inside after reading that Qt3D has re-emerged in a v2.0 and is in fact becoming a part of Qt5 soon and that parts of it is already available for testing as a tech preview. I set out with a simple plan, I would have Qt3D working inside a widget in my existing C++/widgets based application. However the only example I could find that shows how to use Qt3D from C++ is called basicshapes-cpp , and it shows some shapes rendered in a separate OpenGL/Qt3D prepared window (class that extends QWindow ) as opposed from a QWidget . Now I read about the role of QWindow vs.