Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.6k Posts
  • Multi-threading design along with an undo/redo stack

    Unsolved
    2
    0 Votes
    2 Posts
    233 Views
    kshegunovK
    @m3g1dd said in Multi-threading design along with an undo/redo stack: What is the best location for QThread and Worker considering their signal-slot connections? QThread goes into an object in the controlling thread (usually the GUI thread), while the Worker is usually "free", that is I ordinarily don't keep a reference to it anywhere. Still depends on the actual logic, though, you could wrap a "job" based system, or migrate to QtConcurrent::run depending on the actual situation. Typically if you want to break the processing within a secondary thread (a worker one), you'd connect the interruption method (Qt::DirectConnection) to raise some atomic flag, which is checked on each iteration/atom of code that's executed and exit early when needed.
  • How to prevent QListView from calling sizeHint of each item?

    Solved
    4
    0 Votes
    4 Posts
    849 Views
    A
    Well it seems that I've found a solution, so I'll share it here for sake of anyone who has the same problem and googles this thread. First of all, I've found that this is actually a bug in Qt registered back in 2011 and still open: https://bugreports.qt.io/browse/QTBUG-16592 I've added my vote to it, and then decided to try out using QTableView instead of QListView - and, surpise, I managed to make it work, or so it seems. Unlike QListView, QTableView only resizes rows upon explicit request, by calling resizeRowToContents(rowNum). So the trick is to call it in a just-in-time fashion for rows that become visible in the viewport. Here's what I did: Inherit from QTableView (let's call it MyTableView) Replace QListView with MyTableView and initialize it like this in the constructor. This assigns custom item delegate, hides table headers and applies "by row" selection mode: MyTableView::MyTableView(QWidget* parent) : QTableView(parent) { setSelectionBehavior(QAbstractItemView::SelectRows); horizontalHeader()->setStretchLastSection(true); horizontalHeader()->hide(); verticalHeader()->hide(); setItemDelegateForColumn(0, new CustomDelegate(&table)); // for custom-drawn items } In MyTableView, add a QItemSelection private field and a public function that calculates real heights of rows, but only those that are currently visible: QItemSelection _itemsWithKnownHeight; // private member of MyTableView void MyTableView::updateVisibleRowHeights() { const QRect viewportRect = table.viewport()->rect(); QModelIndex topRowIndex = table.indexAt(QPoint(viewportRect.x() + 5, viewportRect.y() + 5)); QModelIndex bottomRowIndex = table.indexAt(QPoint(viewportRect.x() + 5, viewportRect.y() + viewportRect.height() - 5)); qDebug() << "top row: " << topRowIndex.row() << ", bottom row: " << bottomRowIndex.row(); for (auto i = topRowIndex.row() ; i < bottomRowIndex.row() + 1; ++i) { auto index = model()->index(i, 0); if (!_itemsWithKnownHeights.contains(index)) { resizeRowToContents(i); _itemsWithKnownHeights.select(index, index); qDebug() << "Marked row #" << i << " as resized"; } } } Note: if item heights depend on control's width, you need to override resizeEvent(), clear _itemsWithKnownHeights, and call updateVisibleRowsHeight() again. Call updateVisibleRowHeights() after assigning a model to MyTableView instance, so that initial view is correct: table.setModel(&myModel); table.updateVisibleRowHeights(); In fact it should be done in some MyTableView's method that reacts to model changes, but I'll leave it as an exercise. Now all that's left is to have something call updateRowHeights whenever table's vertical scroll position changes. So we need to add the following to MyTableView's constructor: connect(verticalScrollBar(), &QScrollBar::valueChanged, [this](int) { updateRowHeights(); }); Done - it works really fast even with model of 100,000 items! And startup is instantenious! A basic proof-of-concept example of this technique (using pure QTableView instead of subclass) can be found here: https://github.com/ajenter/qt_hugelistview/tree/tableview-experiment Warning: this technique is not battle proven yet and may contain some yet unknown issues. Use at own risk! Hope this helps!
  • widget reappears only after dock resize

    Solved
    3
    0 Votes
    3 Posts
    263 Views
    L
    ok, thanks for replying and the tip. it's that I'm dealing with legacy code and working on qt stuff for the first time. I'll try to use QWidget instead of QDialog. I also found what was causing the issue. It was a call to QWidge::move, so marking it as 'solved'. Thanks!
  • Log/Journal user actions/clicks

    Unsolved log journal user action user clicks
    6
    0 Votes
    6 Posts
    1k Views
    N
    Thanks everyone for your replies. @Pl45m4 @mrjj What I have in mind is: any event (mouse, key, actions on widgets) that changes the state of the user's data should be captured. Let me give a trivial example (one or more actions implied in each step): the user reads x-y data from a file the user manipulates/changes and saves the data based on some provided functionality Out of the box, can Qt capture this sequence of actions? As I say in the OP, the intent is to use this log/journal file to debug instead of asking the user to describe the sequence of actions, and also let the user can replay without having to take the actions again. Thanks again.
  • Convert Plugin interface into a Factory class

    Solved
    7
    0 Votes
    7 Posts
    718 Views
    Christian EhrlicherC
    Enhance your interface, otherwise it's useless.
  • Compacting QDialog when elements are removed

    Unsolved
    4
    0 Votes
    4 Posts
    356 Views
    Christian EhrlicherC
    @Vikram_Newbie said in Compacting QDialog when elements are removed: I expect the window height to be reduced. This will not work automatically, you have to call resize(sizeHint()) by yourself.
  • Comparing two strings in different widgets

    Solved pyqt5 python3
    9
    0 Votes
    9 Posts
    2k Views
    StainopelS
    @Pl45m4 yes I initially used a line edit but ended up changing it to a qtextedit instead. Then using the documentation I was able to get the expected results
  • GraphicsItem's area that can be selected keep size

    Moved Unsolved
    4
    0 Votes
    4 Posts
    314 Views
    Pl45m4P
    @markwang said in GraphicsItem's area that can be selected keep size: if I can express myself clearly The boundingRect does NOT change, but you want to change OR it changed, but you want to have it fixed? EDIT: The area that can be selected keep size ,don't change with boundingRect() 's changed Your pixmap doesn't change when you change the boundingRect?
  • Why all styles are not applied to promoted widget ??

    Solved
    7
    0 Votes
    7 Posts
    888 Views
    Pl45m4P
    @Thank-You It's just the naming of the function. Since Qt has an extra function for alpha values, rgb is for r, g, b only. If you know it, there is nothing special about it. And one can read the documention, to see how it works:)
  • Center QDialog to desktop

    Solved
    9
    0 Votes
    9 Posts
    1k Views
    Thank YouT
    @Stefanoxjx Great😊😊✌
  • Signal and Slot with two different UI class in QT

    Unsolved qtablewidget signal & slot qt c++
    2
    0 Votes
    2 Posts
    1k Views
    JonBJ
    @Rhutu Nothing should "vanish". If you overwrite what is in QTableWidget with something not as you intended then obviously it will cease to show whatever it showed before. If you need to pass additional data from your main window to the slot, you can either do it via a C++ lambda for the slot, or put a slot which is in the main window instead of Obj,SLOT(WriteToFile()), and have that call Obj->WriteToFile(extra). Stop using old-style SIGNAL/SLOT() macros for signals/slots, use https://wiki.qt.io/New_Signal_Slot_Syntax, it's better and it will help you connect correct things.
  • QWebSockets Sending messages with escaped characters and QLineEdit Inputs

    Unsolved
    3
    0 Votes
    3 Posts
    351 Views
    O
    Hi Jon, Sorry for the late reply, I didn't see any come through; Yes I believe my confusion was to do with C++ literals. Thanks for the info on backticks to show code, I'll make sure to use that in the future when asking more questions!
  • QTreeView branch icon background

    Unsolved
    1
    0 Votes
    1 Posts
    156 Views
    No one has replied
  • Compiler can't find the library.

    Unsolved
    4
    0 Votes
    4 Posts
    351 Views
    mrjjM
    @Loc888 Hi Im not sure why it was not mentioned to link to your new lib. But the error "Undefined reference to" suggest that is needed. https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
  • Overriding a protected pure virtual function with a signal

    Unsolved
    19
    0 Votes
    19 Posts
    5k Views
    kshegunovK
    @Christian-Ehrlicher said in Overriding a protected pure virtual function with a signal: Can not work to the parent-child relatonsship Nor moc, more specifically it confuses the hell out of the meta-object system (e.g QMetaObject).
  • How to pass object as pointer - C++ syntax ?

    Unsolved c++
    4
    0 Votes
    4 Posts
    870 Views
    A
    @AnneRanch said in How to pass object as pointer - C++ syntax ?: CCC_LocalAdapters::CCC_LocalAdapters(QObject *parent) : QObject(parent) Thanks fellas. So you want that info QList from CCC_LocalAdapters in your MainWindow class?! Yes, that is my goal. I though I had it using the "second" solution. I'll digest you suggestions and report back later. I am "nursing" my bedridden partner - broken leg and wrist - so have not much time to bang on the keyboard. Later
  • Should *.pro file be part of my project?

    Solved
    7
    0 Votes
    7 Posts
    1k Views
    SGaistS
    Usually, automated systems like GitLab provide a mean to write these scripts. Does your system provide that ?
  • Release and debug

    Unsolved
    4
    0 Votes
    4 Posts
    349 Views
    Christian EhrlicherC
    @aha_1980 Correct since they don't link against the msvcrt runtimes.
  • ICU prebuilt for iOS/Android/MacOS. Where to find?

    Solved
    2
    0 Votes
    2 Posts
    365 Views
    B
    Solution found. Decided to build from sources https://gist.github.com/DanielSerdyukov/188d47e29150622352f1 Issue closed.
  • Macbook with M1 chipset is very attractive, Is QT compatible?

    Unsolved
    5
    0 Votes
    5 Posts
    2k Views
    T
    Thanks so much for your reply!