Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.4k Posts
  • How to generate multiple queries

    Unsolved
    5
    0 Votes
    5 Posts
    434 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
    585 Views
    L
    @SGaist thanks
  • Transparent window has different behavior between Linux platform and Windows platform?

    Unsolved
    10
    0 Votes
    10 Posts
    733 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
    952 Views
    C
    @JoeCFD Thank you for your help
  • StyleSheet for custom widget inherited from `QSlider`

    Unsolved
    1
    0 Votes
    1 Posts
    261 Views
    No one has replied
  • Where is the Qt Visual studio 2022 Extension?

    Unsolved
    5
    0 Votes
    5 Posts
    684 Views
    V
    @SGaist Thanks !
  • Calling a QT Button (C++) From the External Python Script

    Unsolved
    2
    0 Votes
    2 Posts
    168 Views
    SGaistS
    Hi and welcome to devnet, Qt is a C++ framework. From what you wrote your QtQuick GUI calls a C++ backend so the question is: do you really need the GUI to run when using your Python script ? You also have the option of implementing your code with PySide2/6 or PyQt5/6 if your main logic lies in Python.
  • How to use touchevent in QquickWidget on QMenu

    Unsolved
    4
    0 Votes
    4 Posts
    382 Views
    raven-worxR
    @Qt-Jo-Ha you might also need to set it on the QMenu itself
  • Read JSON from LocalHost and Dynamically fill QTableWidget.

    Solved
    9
    0 Votes
    9 Posts
    797 Views
    SGaistS
    Why a static variable ?
  • i need buffer for serial communication

    Unsolved
    3
    0 Votes
    3 Posts
    252 Views
    mrjjM
    Hi I don't know how to think as I've never used a buffer before In your Mainwindow / where serialport lives, add in the .h / class QByteArray data; // the buffer then in the read slot void MainWindow::readData() { data.append(m_serial->readAll( ) ); if (data.size() == 10 ) { // do processing data.clear(); } }
  • Image Gestures Example Windows / Laptops Trackpad

    Unsolved
    1
    0 Votes
    1 Posts
    164 Views
    No one has replied
  • How to convert QTCreator Linux project pro file to C/C++ library?

    Unsolved
    4
    0 Votes
    4 Posts
    349 Views
    artwawA
    @AnneRanch manual in that respect can be confusing as it tends to have all the options for MSVC and Windows. For gcc/clang not really needed. I quite often export parts of my code as a library if said code is/can be useful across the various tools I create, I do remember being confused about how to write it.
  • 0 Votes
    19 Posts
    4k Views
    D
    The QTBluetooth Central API is not supported on any platform. see the first table in Qt Bluetooth
  • Text of styled font is clipped

    Solved
    7
    0 Votes
    7 Posts
    1k Views
    D
    @AhmedAlshawi said in Text of styled font is clipped: I have come across a similar issue but affecting the text on the bottom (see the p's and g's), and I can't seem to solve. Anyone have any idea? Don't change fontsize by stylesheet. Instead use QWidget::setFont() like this: tw = new QTabWidget(); tw->setFont(QFont(tw->font().family(), 16)); looks like: [image: 99d41259-2ceb-404b-94cf-1d54c187656e.jpg] You see - no vertical clipping :) I don't use stylesheets for font-changes at all. QTabBar was the first widget, I had to :( @raven-worx said in Text of styled font is clipped: he cleaner solution would be to intercept the size of the tab via a proxy style (but wont probably not work with a stylesheet style) or subclassing QTabBar and reimplement initStyleOption() (virtual since Qt6 only) Well, that may be true. When I digged into the sources, I thought I'd start to extend QSize QTabBar::tabSizeHint(int index) const ... ... but I decided not to spend too much time into patching Qt. Especially as the workaround costs nothing and works like charming :)
  • Invalid parameter passed to c runtime

    Unsolved
    16
    0 Votes
    16 Posts
    9k Views
    PadawanP
    Haha, Funny thread @J-Hilk thanks for the explanation you gave up there about debugging. It taught me something new
  • QXmlStreamReader throws error when reading a sub element

    Solved
    9
    0 Votes
    9 Posts
    1k Views
    A
    As expected readElementText() cannot read "complete" (tag and content) child elements. However it is possible to ignore child element or to get only their content by using QXmlStreamReader::ReadElementTextBehaviour enum as parameter. Unfortunately this does not provide a straight forward solution to my problem so I had to found a workaround. For example I want to get all the child elements of the project tag (and ignore all grandchildren): while (!xmlReader.atEnd()) { QXmlStreamReader::TokenType token = xmlReader.readNext(); qDebug() << "Next token:" << token << xmlReader.tokenString() << "- at line:" << xmlReader.lineNumber() << "- name:" << xmlReader.name(); if(token == QXmlStreamReader::StartElement && xmlReader.name() == QString("project")) { xmlReader.readNext(); while(xmlReader.name() != QString("project")) { xmlReader.readNextStartElement(); qDebug() << "- tag:" << xmlReader.name() << "- content:" << xmlReader.readElementText(QXmlStreamReader::SkipChildElements); } } } Although it's working it is not very elegant and might not be really reusable (e.g. to get the dependencies in a pom.xml file). Thank you for reading. Have a nice day.
  • A concurrent function run problem.

    Solved
    8
    0 Votes
    8 Posts
    536 Views
    J
    @jsulm Thank you. Now it works good. No GUI blocking.