Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.5k Topics 457.3k Posts
  • QSqlQuery query.value(0).toString()) is Empty

    Solved
    2
    0 Votes
    2 Posts
    486 Views
    K
    additionally if your query returns more than one row, you should iterate via query.next() void GiveGet::on_pushButton_clicked() { int id, copy; QSqlQuery query; id = ui->spinBox->value(); query.prepare("select Inst from list_book WHERE id=?;"); query.addBindValue(id); while(query.next()) { copy = ui->spinBox_2->value() + query.value(0).toInt(); } query.prepare("UPDATE list_book " "SET " "Inst = ?" " WHERE id=?"); query.addBindValue(copy); query.addBindValue(id); if (!query.exec()) { QMessageBox::critical(this, tr("error::"), query.lastError().text()); } else { QMessageBox::warning(this, tr("Saved"),"OK"); } }
  • move qtable with gesture out range

    Solved
    3
    0 Votes
    3 Posts
    232 Views
    P
    @JoeCFD oh thank you, it works to 1000000!!!
  • How do I run an exe file on button clicked in a Qt app?

    Unsolved
    10
    0 Votes
    10 Posts
    13k Views
    X
    @S-ARE said in How do I run an exe file on button clicked in a Qt app?: cd %~dp0 start file.exe AWESOME SOLUTION. THE NEW PROCESS WON'T BLOCK MAIN PROCESS, AND ALSO OUTPUT TO THE CMD WINDOW. ONE STEP , MULTI TARGET。MANY BIRDS WITH ONE STONE~
  • Make QPushButtons have more vibrant colors

    Solved
    9
    0 Votes
    9 Posts
    543 Views
    S
    Hi @mpergand, so I played around with it, and I got some good result Here's what it looks like: [image: 367dfe4e-03f7-48ea-89eb-ce266082b69e.png] Thanks for the suggestion, I think it looks good :) EDIT: Here's the stylesheet I used: background-color: rgb(255, 15, 15); color:black; border: 3px solid rgb(150, 0, 0); border-radius:10px;
  • Cannot use the numeric keypad with Qt Apps

    Unsolved
    3
    0 Votes
    3 Posts
    1k Views
    I
    @Kent-Dorfman Thanks for the link. After using xev I can see that the keycodes and keysyms are different for the numbers at the top row than on the keypad. However I still do not understand why Qt cannot pickup the keypad numbers with numlock enabled when the terminal and other X11 applications can. However, using the shift key + numlock disabled + a keypad number works with Qt.
  • QObject::connect: No such slot

    Solved
    3
    0 Votes
    3 Posts
    2k Views
    J
    Thanks! It worked thanks to the newer syntax.
  • How can I center QCheckBox in QTableView?

    Solved qtableview
    25
    0 Votes
    25 Posts
    6k Views
    C
    @CuriousPan I have fixed the issue. I used pretty dirty, but working trick: set Qt::AlignedCenter right in the delegate: void CenteredCheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = option; const QWidget *widget = option.widget; initStyleOption(&opt, index); QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, widget); if (opt.features & QStyleOptionViewItem::HasCheckIndicator) { switch (opt.checkState) { case Qt::Unchecked: opt.state |= QStyle::State_Off; break; case Qt::PartiallyChecked: opt.state |= QStyle::State_NoChange; break; case Qt::Checked: opt.state |= QStyle::State_On; break; } auto rect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt, widget); opt.rect = QStyle::alignedRect(opt.direction, Qt::AlignCenter/*index.data(Qt::TextAlignmentRole).value<Qt::Alignment>()*/, rect.size(), opt.rect); opt.state = opt.state & ~QStyle::State_HasFocus; style->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &opt, painter, widget); } else if (!opt.icon.isNull()) { // draw the icon QRect iconRect = style->subElementRect(QStyle::SE_ItemViewItemDecoration, &opt, widget); iconRect = QStyle::alignedRect(opt.direction, Qt::AlignCenter/*index.data(Qt::TextAlignmentRole).value<Qt::Alignment>()*/, iconRect.size(), opt.rect); QIcon::Mode mode = QIcon::Normal; if (!(opt.state & QStyle::State_Enabled)) mode = QIcon::Disabled; else if (opt.state & QStyle::State_Selected) mode = QIcon::Selected; QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off; opt.icon.paint(painter, iconRect, opt.decorationAlignment, mode, state); } else { QStyledItemDelegate::paint(painter, option, index); } } bool CenteredCheckBoxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { Q_ASSERT(event); Q_ASSERT(model); // make sure that the item is checkable Qt::ItemFlags flags = model->flags(index); if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled) || !(flags & Qt::ItemIsEnabled)) return false; // make sure that we have a check state QVariant value = index.data(Qt::CheckStateRole); if (!value.isValid()) return false; const QWidget *widget = option.widget; QStyle *style = option.widget ? widget->style() : QApplication::style(); // make sure that we have the right event type if ((event->type() == QEvent::MouseButtonRelease) || (event->type() == QEvent::MouseButtonDblClick) || (event->type() == QEvent::MouseButtonPress)) { QStyleOptionViewItem viewOpt(option); initStyleOption(&viewOpt, index); QRect checkRect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, widget); checkRect = QStyle::alignedRect(viewOpt.direction, Qt::AlignCenter/*index.data(Qt::TextAlignmentRole).value<Qt::Alignment>()*/, checkRect.size(), viewOpt.rect); QMouseEvent *me = static_cast<QMouseEvent *>(event); if (me->button() != Qt::LeftButton || !checkRect.contains(me->pos())) return false; if ((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonDblClick)) return true; } else if (event->type() == QEvent::KeyPress) { if (static_cast<QKeyEvent *>(event)->key() != Qt::Key_Space && static_cast<QKeyEvent *>(event)->key() != Qt::Key_Select) return false; } else { return false; } Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt()); if (flags & Qt::ItemIsUserTristate) state = ((Qt::CheckState)((state + 1) % 3)); else state = (state == Qt::Checked) ? Qt::Unchecked : Qt::Checked; return model->setData(index, state, Qt::CheckStateRole); } Thanks everyone who took part in the discussion.
  • Circular buffer in Qt

    Unsolved
    5
    0 Votes
    5 Posts
    5k Views
    D
    I was looking for this, shame it is not considered standard!
  • Peakcan plugin not working

    Unsolved
    3
    0 Votes
    3 Posts
    333 Views
    M
    Its likely you can just use the socketcan drivers with the PCAN adapter.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • Do I need to call installEventFilter(this)?

    Solved
    6
    0 Votes
    6 Posts
    699 Views
    JonBJ
    @JobRecrd No, installEventFilter sends the events to the eventFilter in the first place. From there you can optionally handle them, or you can just use it to choose to ignore some events while allowing others through for standard processing.
  • How do you center QGraphicsTextItem in its parent?

    Unsolved
    2
    0 Votes
    2 Posts
    1k Views
    D
    For the text alignment, this setY ... text->setY(ellipse->boundingRect().center().y() - text->boundingRect().height()/2); scene()->addItem(ellipse); in void PieView::onMouseOver(PieSeries &s) works: [image: e0c7013d-421e-4567-9059-f36861b238b4.gif] Still couldn't figure out why the remaining slices moves once or more when I first start hovering over slices
  • How to use Signals & Slots to make Inter-Process Communication in Qt ?

    Unsolved
    12
    0 Votes
    12 Posts
    3k Views
    A
    @artwaw thank you for your answers , i know, maybe , i can to do what i want to do with TCP/IP, but i need certainly more and more of time to do it , I thought that Qt D-Bus will win me time, since we have a lot of class Q D-Bus , who can do the work Sincerely, it's the loss of not using so many courses on Windows.
  • How to generate multiple queries

    Unsolved
    5
    0 Votes
    5 Posts
    429 Views
    JonBJ
    @LT-K101 Yes, that is just a UI detail. There is no problem here other than you explaining what these "25 queries" are all about, what exactly you are trying to do/ask.
  • Layout scratching head...

    Unsolved
    21
    0 Votes
    21 Posts
    2k Views
    SPlattenS
    @mchinand , this might look a bit over the top, I have a class clsQtLayout which is derived from QWidget, the reason for this is because the class supports layouts with a scrollable area which can only be accommodated by using a widget to contain everything. After much work the QVBoxLayout works great, I have a form layout inside that can have a fixed height and in my example contains radio buttons, it can be scrollable within the vertical layout. I have tried the same techniques for the QHBoxLayout and this is where I'm having problems, for some reason which I'm not seeing it just doesn't work. Going back to my XML: <layout type="form" height="72" hspacing="0"> <buttongroup id="enSEX" dbfield="vcSex"/> <radiobutton id="rdoM" group="enSEX" text="Male" default="true" position="0,0"/> <radiobutton id="rdoF" group="enSEX" text="Female" position="1,0"/> </layout> This XML behind the scenes creates a QVBoxLayout because the height of the required QFormLayout has a fixed height. A QWidget is created which the QScrollArea connected to. The QScrollArea is then connected to the QVBoxLayout. if ( intFixedHeight > 0 ) { //Create a vertical layout as the container for this layout pobjVBox = new QVBoxLayout; //Create and set-up scroll area mpobjScroller = new QScrollArea; mpobjScroller->setWidget(pobjContainer); mpobjScroller->setFixedHeight(intFixedHeight); pobjVBox->addWidget(mpobjScroller); } pobjLayout = new QFormLayout; //Set-up form pobjLayout->setContentsMargins(0,0,0,0); pobjLayout->setSpacing(0); QString strHorzSpacing(mpobjNode->strGetAttribute( clsXMLnode::mscszAttrSpacingH)); if ( strHorzSpacing.isEmpty() != true ) { ((QFormLayout*)pobjLayout)->setHorizontalSpacing(strHorzSpacing.toInt()); } if ( pobjContainer != nullptr ) { pobjContainer->setLayout(pobjLayout); } This all works fine, the following XML is for the horizontal layout: <layout id="btnbarLO" type="horizontal" width="128"> <groupbox id="btnbar" layout="btnbarLO" properties="background-color:#ff0000;"/> <button id="btnApply" group="btnbar" api="applyChanges"> <subscriber signal="clicked" target="simon2.js@applyButton"/> </button> <button id="btnUndo" group="btnbar" api="undoChanges"/> <button id="btnOK" group="btnbar" api="submitAndClose"/> </layout> And the code in the layout class for this, which should be very similar to the vertical layout: if ( intFixedWidth > 0 ) { //Create a vertical layout as the container for this layout pobjHBox = new QHBoxLayout; //Create and set-up scroll area mpobjScroller = new QScrollArea; mpobjScroller->setWidget(pobjContainer); mpobjScroller->setFixedWidth(intFixedWidth); pobjHBox->addWidget(mpobjScroller); } pobjLayout = new QHBoxLayout; //Set-up form pobjLayout->setContentsMargins(0,0,0,0); pobjLayout->setSpacing(0); QString strHorzSpacing(mpobjNode->strGetAttribute( clsXMLnode::mscszAttrSpacingH)); if ( strHorzSpacing.isEmpty() != true ) { ((QHBoxLayout*)pobjLayout)->addSpacing(strHorzSpacing.toInt()); } if ( pobjContainer != nullptr ) { pobjContainer->setLayout(pobjLayout); } However this isn't working and the results are as shown in the original screenshot: [image: 90103c88-c687-4459-883b-84d414bc1e2e.png] I've set the background colour of the QGroupBox to red to clarify where it is. [edit] I can see it isn't clear, so elsewhere in my node handling code there is this logic where nodes are appended to parent nodes: QWidget* pobjWChild(pobjChild->pobjGetWidget()); if ( pobjWChild != nullptr && mstrName.compare(clsXMLnode::mscszNodeLayout) == 0 ) { //Yes, does the parent have a layout? QLayout* pobjLayout(pobjGetLayout()); if ( pobjLayout != nullptr ) { QString strType(strGetAttribute(clsXMLnode::mscszAttrType)); QFormLayout* pobjForm(qobject_cast<QFormLayout*>(pobjLayout)); //Add the widget for the layout if ( pobjForm != nullptr && strType.compare(clsXMLnode::mscszLayoutVertical) == 0 ) { pobjForm->addRow(pobjWChild); } else { pobjLayout->addWidget(pobjWChild); } } }
  • Preview forms before saving into database

    Unsolved
    9
    0 Votes
    9 Posts
    584 Views
    L
    @SGaist thanks
  • Transparent window has different behavior between Linux platform and Windows platform?

    Unsolved
    10
    0 Votes
    10 Posts
    728 Views
    S
    Qt has a feature for this, i.e. masking of widgets. Have a look at their shaped clock example: https://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html
  • QT program crashing when using the extern keyword on a global object

    Unsolved
    16
    0 Votes
    16 Posts
    1k Views
    Christian EhrlicherC
    @JonB said in QT program crashing when using the extern keyword on a global object: This may or may not be a good way to design your software This is no question - the design is bad (the nicest word I could find for it, sorry)
  • Interfaces must inherit QObject?!

    Solved
    24
    0 Votes
    24 Posts
    5k Views
    JonBJ
    @JKSH said in Interfaces must inherit QObject?!: OP forgot to re-run qmake (or delete the build directory) after making ICake inherit QObject and adding the Q_OBJECT macro. They can't. Thank you, this makes a lot more sense then!
  • move photo from right to left on widget

    Solved
    12
    0 Votes
    12 Posts
    948 Views
    C
    @JoeCFD Thank you for your help