Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.5k Topics 457.3k Posts
  • Qt SerialPort.canReadLine() ?

    Unsolved
    16
    0 Votes
    16 Posts
    9k Views
    K
    For me all works: https://codereview.qt-project.org/#/c/185925/
  • Bring Widget To front

    Unsolved
    6
    0 Votes
    6 Posts
    4k Views
    A
    @Shahina Here ya go, this should help you understand the problem and there is a solution in it as well but it is windows specific. http://stackoverflow.com/questions/5919928/qt-need-to-bring-qt-application-to-foreground-called-from-win32-application I don't know of a good Qt solution for you. What you are describing is how window managers are meant to work. In it's mind your application is no long the foreground app and shouldn't be able to bring windows to the foreground without using an always on top type of setting. Which still wouldn't give you focus it would just force your window on top. Not the same thing.
  • Cannot pass variable to another Dialog

    Unsolved
    18
    0 Votes
    18 Posts
    4k Views
    jsulmJ
    @t0msk You could use the C function memcpy() - it is much more efficient compared to your solution and is only one line :-)
  • Strange problem with a method in Qt

    Unsolved
    7
    0 Votes
    7 Posts
    1k Views
    SGaistS
    Hi, Why are you creating another application in insertDataToLabels ?
  • QSS border-width transition with rounded corners

    Unsolved stylesheet
    4
    0 Votes
    4 Posts
    4k Views
    SGaistS
    Looks like a rendering problem of the style used to render widget modified by a stylesheet.
  • How to map QRadioButtons to a QDataWidgetMapper

    Solved
    7
    0 Votes
    7 Posts
    1k Views
    P
    Thanks! setAutoExclusive did the job.
  • Qt Designer have to make buttons huge to make app look normal. Why?

    Unsolved
    2
    0 Votes
    2 Posts
    383 Views
    SGaistS
    Hi and welcome to devnet, Are you working on a HighDPI screen ? Note that the upload feature is currently broken, you should use an image sharing site to show your images.
  • Splash screen in not showing in exec file

    Solved
    11
    0 Votes
    11 Posts
    3k Views
    SGaistS
    Did you follow that guide ?
  • Show value entered in QTextEdit by user in a QLabel when user click submit button

    Unsolved
    5
    0 Votes
    5 Posts
    1k Views
    VRoninV
    @sanjay1155 said in Show value entered in textedit by user in a label when user click submit button: in Mainwindow::Mainwindow() function yes, in the constructor slot when my button is clicked if you already have a slot connected to QPushButton::clicked just add label->setText(textEdit->toPlainText()); to it instead of using my code
  • This topic is deleted!

    Unsolved
    9
    0 Votes
    9 Posts
    101 Views
  • Updating ListView selection when a model resets

    Unsolved
    11
    0 Votes
    11 Posts
    2k Views
    SGaistS
    In that case, wouldn't it be simple to take the original humbler code and modify it to look like you want ?
  • Set background of specific row in QTableView

    Unsolved
    2
    0 Votes
    2 Posts
    3k Views
    VRoninV
    You can set it at the model level (all views connected to the model are affected) void setRowColor(QAbstractItemModel* model, int row, const QBrush& color, const QModelIndex& parent = QModelIndex()){ if(!model) return; if(row<0 || row>=model->rowCount(parent)) return; const int colCount = model->columnCount(parent); for (int j = 0; j < colCount; ++j) model->setData(model->index(row,j,parent),color,Qt::BackgroundRole); } or use a delegate for the specific view (the one below lets you specify the color for entire row and column and for individual cell): #include <QStyledItemDelegate> #include <QApplication> #include <QHash> class BackGroungColorDelegate : public QStyledItemDelegate { Q_OBJECT Q_DISABLE_COPY(BackGroungColorDelegate); public: explicit BackGroungColorDelegate(QObject *parent = Q_NULLPTR) :QStyledItemDelegate(parent){} virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE{ Q_ASSERT(index.isValid()); QStyleOptionViewItem opt = option; initStyleOption(&opt, index); if (!index.parent().isValid()) { if (hasCellColor(index.row(), index.column())) opt.backgroundBrush = colorForCell(index.row(), index.column()); } const QWidget *widget = option.widget; QStyle *style = widget ? widget->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget); } void setColorForRow(int row, const QBrush& val){ m_rowColors[row] = val; } QBrush colorForRow(int row) const { return m_rowColors.value(row); } void removeColorForRow(int row){ m_rowColors.remove(row); } void clearRowColors(){ m_rowColors.clear(); } void setColorForCol(int col, const QBrush& val) { m_colColors[col] = val; } QBrush colorForCol(int col) const { return m_colColors.value(col); } void removeColorForCol(int col) { m_colColors.remove(col); } void clearColColors() { m_colColors.clear(); } void setColorForCell(int row, int col, const QBrush& val){ m_cellColors[cellKey(row, col)] = val; } QBrush colorForCell(int row, int col) const { return m_cellColors.value(cellKey(row, col), m_rowColors.value(row, m_colColors.value(col))); } void removeColorForCell(int row, int col) { m_cellColors.remove(cellKey(row, col)); } void clearCellColors() { m_cellColors.clear(); } private: QHash<quint64,QBrush> m_cellColors; QHash<int, QBrush> m_rowColors; QHash<int, QBrush> m_colColors; Q_DECL_CONSTEXPR quint64 cellKey(int row, int col) const { return (static_cast<quint64>(row) << 32) | static_cast<quint64>(col); } protected: bool hasCellColor(int row, int col) const{ return m_cellColors.contains(cellKey(row, col)) || m_rowColors.contains(row) || m_colColors.contains(col); } };
  • QTableView into 2D array

    Unsolved
    2
    0 Votes
    2 Posts
    737 Views
    VRoninV
    Since "2D array" is quite generic, I made the algorithm quite generic as well template<class T> void modelToArray(const QAbstractItemModel* const model, T& array2d, const QModelIndex& parent = QModelIndex(), int role = Qt::DisplayRole) { if(!model) return; const int rowCount = model->rowCount(parent); const int colCount = model->columnCount(parent); for (int i = 0; i < rowCount; ++i) { for (int j = 0; j < colCount; ++j) array2d[i][j] = model->index(i, j, parent).data(role).value<std::remove_reference<decltype(array2d[i][j])>::type>(); } }
  • This topic is deleted!

    Solved
    2
    0 Votes
    2 Posts
    25 Views
  • Send file to trash

    Unsolved
    4
    0 Votes
    4 Posts
    699 Views
    mrjjM
    @Sikarjan Hi, its a feature of the OS so its doubtful it will ever be included as something cross platform. But the SO post has code both for win and linux so u get some for free. :)
  • How to declare a QFile as a member class

    Solved
    2
    0 Votes
    2 Posts
    2k Views
    mrjjM
    @aurquiel Hi QFile can also set the info via functions http://doc.qt.io/qt-5/qfile.html#setFileName and for out(&file); http://doc.qt.io/qt-5/qdatastream.html#setDevice The reason it dont work is that the first syntax is the constructor and that cant work the same when in .h but both classes have function to set it. Alternativ u can new them but its better with the setX functions. ( IMHO)
  • How to use new signal/slot syntax in Qt5.6?

    Solved
    11
    0 Votes
    11 Posts
    4k Views
    kahlenbergK
    It worked. I declared the function dumpReceivedData as static mistakenly. I deleted static keyword and it worked. I also tested lambda function. It also worked. Thanks a lot.
  • How to expand tabs in QTabWidget

    Solved
    5
    0 Votes
    5 Posts
    6k Views
    K
    @mostefa you're right. I will update my code. Thanks again.
  • Error on QEventLoop::exec() under windows (works well under linux)

    Solved
    15
    0 Votes
    15 Posts
    4k Views
    S
    @VSRonin, @jsulm I have done the change in the two part of my function where I have an event loop and now it doesn't crash anymore (even with a lot of requests) and it works.
  • How to set QPlainTextEdit 's text to mapper->currentIndex?

    Solved
    3
    0 Votes
    3 Posts
    649 Views
    P
    Thanks it works!