Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.5k Topics 457.3k Posts
  • QTableView comma as decimal separator

    Solved
    8
    0 Votes
    8 Posts
    943 Views
    nicmoraisN
    Solved by setting the values as doubles insted of floats. Thanks a lot for your attention, guys.
  • 0 Votes
    3 Posts
    476 Views
    M
    @Christian-Ehrlicher Thank you for your reply, it is helpful to me. In addition, I would like to ask another question. If I want to filter this way, I only want the main window to receive messages, but I don't want the child window control QWidget to receive messages. Can this be achieved? Or can it only be achieved by overloading the nativeEvent function on QMainWindow? Hope your reply
  • 0 Votes
    4 Posts
    687 Views
    Christian EhrlicherC
    @jronald said in QAbstractItemModel::rowsMoved problem when moving a row to the last in the same parent: which is out of range, is it as expected? Yes, it's correct. If the start is before the end and you want to know where it is now you have to do some basic math. rowsMoved() simply informs you about what was given to beginMoveRows()
  • need help on tristate toolbutton creation

    Solved
    14
    0 Votes
    14 Posts
    955 Views
    D
    Hi Pl45m4, toolbar seems to be a crazy environment. I shouted the 'F'-word several times. Had lot of crashes, but finally I think I got it. Not perfect, but a solution, I can live with ;) Every posibility, I thought I should work with is blocked/prohibited. Either function not virtual, or no function used for access ... QWidgetAction is the only posibility to get individual widgets into a toolbar. But that widget will be reduced to a stupid painter subject. The factory action is still used as an action (well - I thought it would be just a factory action, but it is not. Stil a complete QAction!). After I got that point, it was straightforward to implement - MultiStateButton - declaration: class MultiStateToolButton : public QToolButton { Q_OBJECT public: MultiStateToolButton(ValueModel* vm, const QIcon& s0Icon, const QIcon& s1Icon, const QIcon& s2Icon, QWidget* parent = nullptr); protected slots: void stateChanged(const QVariant& state); private: ValueModel* model; const QIcon& s0Icon; const QIcon& s1Icon; const QIcon& s2Icon; }; I implemented it for 3 States, but it could be adapted to any number of states. ValueModel is used to hold the buttons state - as in my application the buttons state can be changed from outside of my application ... model could be a Qt-property as well. MultiStateButton - definition: MultiStateToolButton::MultiStateToolButton(ValueModel* vm, const QIcon& s0Icon, const QIcon& s1Icon, const QIcon& s2Icon, QWidget* parent) : QToolButton(parent) , model(vm) , s0Icon(s0Icon) , s1Icon(s1Icon) , s2Icon(s2Icon) { setIcon(this->s0Icon); connect(model, &ValueModel::valueChanged, this, &MultiStateToolButton::stateChanged); } void MultiStateToolButton::stateChanged(const QVariant& state) { qDebug() << "MultiStateButton::stateChanged ... " << state; switch (state.toInt()) { case 2: setIcon(s1Icon); break; case 3: setIcon(s2Icon); break; default: setIcon(s0Icon); break; } } The hardest point for me to get rid of was, that the toolbutton works fine with const references to icons, but the QWidgetAction will crash with icons as references. As I could not use one QIcon with multiple pixmaps, I decided to use one QIcon for each picture. So the subclass of QWidgetAction is straight forward: class MultiStateAction : public QWidgetAction { Q_OBJECT public: MultiStateAction(ValueModel* vm, const QIcon& s0Icon, const QIcon& s1Icon, const QIcon& s2Icon, QWidget* parent = nullptr); QWidget* createWidget(QWidget* parent) override; private: ValueModel* model; QIcon s0Icon; QIcon s1Icon; QIcon s2Icon; }; I started with const references in the widget action, as I thought, I only have to store the parameters for widget creation later on ... MultiStateAction::MultiStateAction(ValueModel* vm, const QIcon& s0Icon, const QIcon& s1Icon, const QIcon& s2Icon, QWidget *parent) : QWidgetAction(parent) , model(vm) , s0Icon(s0Icon) , s1Icon(s1Icon) , s2Icon(s2Icon) { setIcon(s0Icon); setText("MultiStateFactoryAction"); } QWidget *MultiStateAction::createWidget(QWidget *parent) { QToolButton* tb = new MultiStateToolButton(model, s0Icon, s1Icon, s2Icon, parent); tb->setDefaultAction(this); return tb; } QToolButton::setDefaultAction() is the most important step. Without that, the button does not emit a triggered signal. With that function call, button and action emit a triggered signal. Creation of toolbar (in mainwindow or similar) looks like: Window::Window() : model(new ValueModel("state", 0)) , tb(new QToolBar) , a1(new QAction("A")) , a2(new QAction("B")) , a3(new QAction("C")) , a4(new QAction("D")) , msa(new MultiStateAction(model , QIcon(":/res/doc.png") , QIcon(":/res/hand.png") , QIcon(":/res/ok.png"))) { setLayout(new QVBoxLayout); setupActions(); connectActions(); } void Window::setupActions() { tb->setIconSize(QSize(100, 100)); tb->addAction(a1); tb->addAction(a2); tb->addAction(a3); tb->addAction(msa); tb->addAction(a4); layout()->addWidget(tb); } First I had no call of setDefaultAction used and got no signal from the multistatebutton. So I tried several ways to get the button-press-event ... As said - button state can be changed outside of my app, so the plain actions simulate external status change ... void Window::connectActions() { connect(a1, &QAction::triggered, this, [=]() { qDebug() << "A"; model->setValue(0); }); connect(a2, &QAction::triggered, this, [=]() { qDebug() << "B"; model->setValue(1); }); connect(a3, &QAction::triggered, this, [=]() { qDebug() << "C"; model->setValue(2); }); connect(a4, &QAction::triggered, this, [=]() { qDebug() << "D"; model->setValue(3); }); connect(msa, &QAction::triggered, this, [=]() { qDebug() << " - MultiStateAction triggered ... !"; }); QToolButton* multiStateButton = static_cast<QToolButton*>(tb->widgetForAction(msa)); if (multiStateButton) { connect(multiStateButton, &QToolButton::triggered, this, [=]() { qDebug() << "MultiStateToolButton clicked ..."; }); } else { throw QString("OUPS - toolbar has no MultiStateToolButton button!"); } } @Pl45m4 thank you very much for your help!
  • fakevim and open files

    Unsolved
    2
    0 Votes
    2 Posts
    295 Views
    JonBJ
    @U7Development I have not used FakeVim, so just a guess/suggestion: :.!touch mynewfile.h ?
  • 0 Votes
    2 Posts
    177 Views
    enjoysmathE
    Nevermind! Modifying DeleteItems with a _connectivity dictionary seems to have solved the problem. class DeleteItems(UndoCmd): Parent, Source, Dest = range(3) def __init__(self, items:list, canvas:LanguageCanvas): super().__init__() self._items = items self._canvas = canvas self._connectivity = {} def redo(self): for item in self._items: if isinstance(item, Arrow): self._connectivity[id(item)] = (item.parentItem(), item.source, item.destination) item.set_source(None) item.set_destination(None) elif isinstance(item, (Object, Text)): self._connectivity[id(item)] = item.parentItem() item.setParentItem(None) self._canvas.removeItem(item) def undo(self): for item in self._items: if isinstance(item, Arrow): parent, source, dest = self._connectivity[id(item)] item.set_source(source) item.set_destination(dest) elif isinstance(item, (Object, Text)): parent = self._connectivity[id(item)] item.setParentItem(parent) self._canvas.addItem(item) I honestly thought this would be much tougher to fix.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    9 Views
    No one has replied
  • How to display full text in context menu for QHeaderView?

    Solved
    4
    0 Votes
    4 Posts
    327 Views
    jronaldJ
    @SGaist said in How to display full text in context menu for QHeaderView?: Did you try with 6.2.1 just in case it was fixed in between ? Tried Qt 6.2.1, the problem still exists.
  • #error "The header file 'videostreamer.h' doesn't include <QObject>."

    Unsolved
    8
    0 Votes
    8 Posts
    727 Views
    JKSHJ
    @wrosecrans said in #error "The header file 'videostreamer.h' doesn't include <QObject>.": tldr: solve linker errors about missing symbols by linking the relevant library +1 And projects that use Qt should also use a build system (e.g. qmake or CMake), not call g++ directly not by hacking on includes in unrelated header files. To be fair, OP didn't seem to hack any headers. They only looked at a moc-generated header and misinterpreted it.
  • How QPainter repaint viewport() and how to optimize it?

    Unsolved
    2
    0 Votes
    2 Posts
    494 Views
    Christian EhrlicherC
    Draw the stuff outside your paintEvent() and only blit the QImage/QPixmap in the paintEvent()
  • QTableWidget automatically sizes rows too large

    Solved
    20
    0 Votes
    20 Posts
    7k Views
    P
    @Publicnamer OK I believe I found the bug. At the end of my function which fills the table with data, I had a call to: void QTableView::resizeRowsToContents() This was overriding all of my attempts to programmatically set the ideal row sizes but more importantly it was setting bogus row heights.
  • QTableWidget segmentation fault with setTextAlignment

    Unsolved
    6
    0 Votes
    6 Posts
    632 Views
    JonBJ
    @VRonin [Totally out of my head, not tested.] My understanding was that if you use the setData() level, that's fine, but I thought that did not create a QTableWidgetItem item for it. QTableWidget does not reimplement setData(), so you're saying it would have to do it on dataChanged() signal? (And that doesn't get emitted if you're not actually changing the value.) EDIT OK looked on woboq, agreed, it has internal QTableModel::setData() which does as you say about creating the item.
  • Qt Java function call via JNI

    Unsolved
    5
    1 Votes
    5 Posts
    795 Views
    raven-worxR
    @nsourl yes, any IPC mechnism is applicable for you. https://doc.qt.io/qt-5/ipc.html I would say take the one which integrates the easiest for your needs on both sides. For example TCP/IP works in all frameworks and systems, but requires to setup a custom protocol for data transfer. Or use a RPC lib as you mentioned.
  • Template Q_GADGET with Q_ENUM

    Solved
    9
    0 Votes
    9 Posts
    1k Views
    VRoninV
    @St-Stanislav said in Template Q_GADGET with Q_ENUM: Yes, I found my typo, I meant "templated" :) There is a workaround for this: https://github.com/woboq/verdigris but I don't think it's worth it in your case
  • QInputDialog::setInputMode doesn't work

    Solved
    5
    0 Votes
    5 Posts
    409 Views
    S
    Hi @SGaist, thank you, that is what I was looking for. It works perfectly. Code: QString text; QInputDialog getCustomText; getCustomText.setOption(QInputDialog::UsePlainTextEditForTextInput); getCustomText.setWindowTitle("Set a custom course"); getCustomText.setLabelText("Type in or paste an article."); if (getCustomText.exec() == QInputDialog::Accepted) { text = getCustomText.textValue(); }
  • How does the UI have different user display modes

    Solved
    6
    0 Votes
    6 Posts
    462 Views
    tovaxT
    @J-Hilk Thank you for your patience , your idea solved my question.
  • How to remove this effect?

    Solved
    6
    0 Votes
    6 Posts
    565 Views
    raven-worxR
    @Emon-Haque i dont see an additional gap. you may want to read this: https://doc.qt.io/qt-5/coordsys.html
  • Why does QPainter::boundingRect returns 0 0?

    Solved
    3
    0 Votes
    3 Posts
    461 Views
    D
    @mpergand, yes now I get 192 16 148 32.
  • cURL - The program has unexpectedly finished. Crash!

    Unsolved
    10
    0 Votes
    10 Posts
    1k Views
    D
    @Hayden-Harber Did you get any solution for this. i have encountered the same problem like this.
  • Why the pointer of QVector always change when use QVector as parameter of signal?

    Unsolved
    7
    0 Votes
    7 Posts
    534 Views
    MozzieM
    @jsulm Thank you very much!